use current group in part of jinja of a template

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

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.

Great!
This is what I needed:

{% for host in play_hosts %}

Thank you.