Nested variables and "with_items: groups"

172 views
Skip to first unread message

David Goodall

unread,
Jan 13, 2015, 10:28:08 AM1/13/15
to ansible...@googlegroups.com
Hi,

I used to have this:
with_items: groups['masters']

I have now changed the group name to reflect the project name, which is entered into the "project_name" variable when the playbook is run.
e.g. if the project is "test", the group will be "test-masters"

In the "with_items:" statement, I would like to be able to replace "masters" with something like {{ project_name }}-masters.

The latest attempt is:
with_items: groups['"ansible_" + project_name + "-masters"']

I have been trawling this group and have tried various incantations, all to no avail so far.

For bonus points, I also have this in a jinja2 template:
{% for host in groups['masters'] %}
 - which will need the same treatment...

Any help appreciated!
Best regards,
David

David Goodall

unread,
Jan 13, 2015, 11:43:35 AM1/13/15
to ansible...@googlegroups.com
OK, figured it out finally:

with_items: "{{ groups[project_name + '-masters'] }}"

{% for host in groups[project_name + '-masters'] %}
Reply all
Reply to author
Forward
0 new messages