Ansible - multiple roles -
i trying run multiple roles using with_items
command, getting error:
"error! 'item' undefined"
role.yml
:
--- - hosts: '{{ host }}' become: yes roles: - role: "{{item}}" with_items: "{{ roles }}"
here command:
ansible-playbook -i ./inventory/dev ./playbooks/role.yml --extra-vars='{"host": "db", "roles": ["mysql", "apache"]}'
you cannot way. with_
loops not valid roles.
if anything, need provide list of roles roles:
directive, syntax list of host groups hosts: '{{ host }}'
. problem is: ansible not resolve variable roles, roles: '{{ roles }}'
not work.
what can do, however, use include_role module in can access variables.
no, include_role module doesn't take {{ item }}
with_items
value name
either.
so workaround can think of (assuming don't want process json beforehand) include roles statically:
tasks: - include_role: name: "mysql" when: "'mysql' in roles" - include_role: name: "apache" when: "'apache' in roles"
the roles need exist on control machine anyway, names predefined.
Comments
Post a Comment