Hi there,
first post here so just a quick thank you to everybody who has contributed
to ansible, it'a fantastic piece of software.
I'm trying to specify hosts and roles at run time from cli while using a
template playbook like this:
# ideal playbook
---
- hosts: "{{var_hosts}}"
roles:
- { role: {{item}} }
with_items: "{{var_roles}}"
# cli call
ansible-playbook play.yml -e "var_hosts=host, var_roles=[role1, role2]"
This however did not work for me, it just seems it's not possible to use
with_items on "roles".
Since I'm on 2.2 I thought I may use include_role, so I tried this:
---
- hosts: "{{var_hosts}}"
tasks:
- name: include roles
include_role:
name: "{{item}}"
with_items: {{var_roles}}
this however failed with ERROR! 'item' is undefined
I thought I might not be able to use vars there, but if I define a var such
as "role" and use it instead of "item" it works:
- hosts: "{{var_hosts}}"
vars:
role: test
tasks:
- name: include roles
include_role:
name: "{{role}}"
am I doing something wrong? is there any way I can pass roles from cli and
load them dynamically?
thanks,
Spike
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/f77be684-6507-4d88-ad79-8969048b2b2c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.