Cannot iterate over hosts in group of groups inside of a template

35 views
Skip to first unread message

Juergen Brendel

unread,
Apr 8, 2014, 11:24:20 PM4/8/14
to ansible...@googlegroups.com

Hello!

I don't seem to be able to iterate over the hosts of a group of groups
within a template.

My inventory file looks similar to this:

[group1]

[group2]

[group3:children]
group1
group2

The groups "group1" and "group2" are initially left empty. However, they
are populated with dynamically created EC2 instances by some playbook.

Later on, I have some tasks, which are just for hosts in group3:

hosts: group3
tasks:
- ...

This works as expected, so I know that Ansible knows what group3 is and
what it consists of.

However, when I try to iterate over the hosts of group3 from within a
template (in some other tasks), it does not work:

# Some template file
{% for host in groups['group1'] %} this works {% endfor %}
{% for host in groups['group2'] %} this works {% endfor %}
{% for host in groups['group3'] %} this does NOT work {% endfor %}

By "not working" I mean: The template engine seems to think that the
group3 is just empty.

Is that as intended? Is it a bug? Or am I just doing something wrong?

Any help would be greatly appreciated...

Thank you very much!

Juergen




Michael DeHaan

unread,
Apr 9, 2014, 10:10:24 AM4/9/14
to ansible...@googlegroups.com
It's not really intended that you can mix static groups and dynamic groups like this.

Each inventory source is mostly it's own thing.

You would probably want to amend your inventory script so that the hosts came back in more groups as presently implemented.




Juergen




--
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 ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/1397013860.5876.33.camel%40localhost.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages