At the moment I'm attempting to loop over a YAML dict of OS user <-> DB user mappings (for pg_ident.conf) and am running into an error:
# host_vars/<hostname>
postgres_users:
baltar:
os: "{{ username }}"
db: "{{ db_name }}"
caprica:
os: "{{ username }}"
db: "{{ db_name }}"
# pg_ident.conf.j2
{% for user in postgres_users %}
{{ user.db }} {{ user.os }} {{ user.key }}
{% endfor %}
# roles/postgresql/tasks/postgres.yml
- name: copy postgres ident maps
template: src=pg_ident.conf.j2 dest=/etc/postgresql/9.3/main/pg_ident.conf owner=postgres group=postgres mode=0640
register: postgres_ident
with_dict: postgres_users
# error message
TASK: [postgres | copy postgres ident maps] ***********************************
fatal: [default] => {'msg': "AnsibleUndefinedVariable: One or more undefined variables: 'str object' has no attribute 'db'", 'failed': True}
fatal: [default] => {'msg': 'One or more items failed.', 'failed': True, 'changed': False, 'results': [{'msg': "AnsibleUndefinedVariable: One or more undefined variables: 'str object' has no attribute 'db'", 'failed': True}]}
This fails with "too many values to unpack".
Which is the functional and favored approach? I'd rather the map keys be the names but can't seem to get this to work.