use current group in part of jinja of a template

82 views
Skip to first unread message

Yariv Graf

unread,
Mar 25, 2015, 9:54:43 AM3/25/15
to ansible...@googlegroups.com
Hi,
I have this code of template for zookeeper role:

{% for host in groups['all'] %}
server.{{ hostvars[host].zookeeper_id }}={{ hostvars[host]['ansible_hostname'] }}:2888:3888
{% endfor %}


In this example it applies for all hosts in the inventory file.
I know you can specify a group like : groups['zookeepers'] but I need to apply it on the current group the role runs on.
Is it possible?

Thanks

Matt Martz

unread,
Mar 25, 2015, 10:48:10 AM3/25/15
to ansible...@googlegroups.com
There isn't really a current group that the role is running on.

You might be able to use the "group_names" variable, however since a host can be in multiple groups, that is a list and not singular.  You might however still might be able to make it work.

Your other option is instead to use "play_hosts" which is an explicit list of hosts targeted by the play.  That may suit your needs better than trying to guess the group.

--
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/0f50779a-7664-4496-b264-228f7b64fb00%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Matt Martz
@sivel
sivel.net

Yariv Graf

unread,
Mar 25, 2015, 11:38:44 AM3/25/15
to ansible...@googlegroups.com
Great!
This is what I needed:

{% for host in play_hosts %}

Thank you.
Reply all
Reply to author
Forward
0 new messages