I have a task in an Ansible playbook that is supposed to iterate with a list of users and do a lineinfile to enable access to a postgress database:
- name: Postgres localhost access
lineinfile:
dest: "{{postgres_dest}}/data/pg_hba.conf"
line: "host all {{item.user}} 127.0.0.1/32 trust"
regexp: "^host[\s\t]*all[\s\t]*{{item.user}}[\s\t]*127.0.0.1/32[\s\t]*trust"
insertbefore: EOF
with_items: "{{postgres_users}}"
notify: postgres reload
tags:
- postgres
- postgres_hba
the problem I'm getting is that ansible thinks that the {{item.user}}
is not being escaped with ""
, which actually is not true, since this will expand due to the ""
of the whole line. The exact error I get:
Syntax Error while loading YAML script, jenkins.yml
Note: The error may actually appear before this position: line 156, column 9
line: "host all {{item.user}} 127.0.0.1/32 trust"
regexp: "^host[\s\t]*all[\s\t]*{{item.user}}[\s\t]*127.0.0.1/32[\s\t]*trust"
^
We could be wrong, but this one looks like it might be an issue with
missing quotes. Always quote template expression brackets when they
start a value. For instance:
with_items:
- {{ foo }}
Should be written as:
with_items:
- "{{ foo }}"
any ideas on how to do this?