Hello,
i want to fill items from file. example below work nice, but if i tried items fill from separate file, then it doesnt work.
-
postgresql_user:
db: “{{ item.db }}”
name: “{{ item.name }}”
password: “{{ item.password }}”
port: “{{ item.port }}”
with_items:- {db: test33, name: test111, password: secret, port: 5432 }
- {db: test33, name: test222, password: secret, port: 5432 }
-
postgresql_privs:
role: “{{ item.name }}”
database: “{{ item.database }}”
privs: “{{ item.privs }}”
type: “{{ item.type }}”
obj: “{{ item.obj }}”
with_items:- { name: test111, database: test33, privs: ALL, type: table, obj: new }
- { name: test222, database: test33, privs: SELECT, type: table, obj: new }
i tried example below but it doesnt work as i expect. I also tried to include file, but it didnt help too
- name: get list of users
include_vars:
file: …/vars/main.yml
name: users
role/name/vars/main.yml
users:
- { name: user144, username: test144, db: test33, password: secret, priv: ALL }
role/name/tasks/main.yml
- postgresql_user:
db: “{{ item.db }}”
name: “{{ item.username }}”
password: “{{ item.password }}”
priv: “{{ item.priv }}”
with_items:- “{{ users }}”
result:
fatal: [default]: FAILED! => {“msg”: “The task includes an option with an undefined variable. The error was: ‘dict object’ has no attribute ‘password’\n\nThe error appears to have been in ‘/home/m/Documents/Vagrant/postgresql/tests/roles/psql/tasks/main.yml’: line 6, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- postgresql_user:\n ^ here\n\nexception type: <class ‘ansible.errors.AnsibleUndefinedVariable’>\nexception: ‘dict object’ has no attribute ‘password’”}
thank you