Hi,
For one of the playbook I am trying to write, I am trying to allow the input of a dynamic role list.
However, this does not seem to work:
- name: “Apply extra roles (see .myfile.yml)”
hosts: all
gather_facts: true
sudo: true
user: vagrant
roles: extra_roles
Does it make sense? Is it supported? Or should I try to do this differently?
I’m not sure where you expect “.myfile.yml” to be loaded.
Can you elaborate?
Its a bit tricky to explain… at any rate, my question really is about using a variable as a role list. Is this doable/logical/stupid?
You can achieve this something like this if you … really … want to.
-
hosts: all
tasks:
-
group_by: key=should-foo-{{ ‘foo’ in my_roles }}
-
group_by: key=should-bar-{{ ‘bar’ in my_roles }}
-
hosts: should-foo-True
roles:
-
foo
-
hosts: should-bar-True
roles:
-
bar
Otherwise you can’t because plays affect all hosts and the variables for different hosts would be different.
It’s better to leave playbooks as the concept that map hosts to roles and keep it simple.
I’m trying to accomplish something similar, where I’d have a list of roles defined in the group_vars/all file (where I’d disable certain roles by just commenting them out):
`
Roles must be a list, but the value of roles is not templated.
It expects this to be in the playbook.
It wouldn’t work with inventory variables anyway, so there’s not much point.
Inventory variables happen after tasks start getting parsed.
Any solutions for this? I am trying to do the same but no luck!