# 'group\_names' now available as a variable in templates

**URL:** <https://forum.ansible.com/t/group-names-now-available-as-a-variable-in-templates/11467>\
**Category:** Ansible Project\
**Created:** [April 28, 2012, 9:42pm UTC](https://forum.ansible.com/t/group-names-now-available-as-a-variable-in-templates/11467 "2012-04-28T21:42:50Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [April 28, 2012, 9:42pm UTC](https://forum.ansible.com/t/group-names-now-available-as-a-variable-in-templates/11467/1 "2012-04-28T21:42:50Z")

</div>

On the devel branch, you can now do clever things in templates like this thanks to a patch from Jeroen Hoekx:

{% if 'oracle' in group\_names %}  
This is an oracle node  
{% else %}  
This is not oracle  
{% endif %}

This may be easier for some things than the "first\_available\_file" trick emailed earlier, but obviously this requires putting something into a group.  
It is explicit, not discovered from looking at the host.

This will also might be useful in the "only\_if" directive to have a playbook that was MOSTLY the same on all nodes, but had a step  
that should be skipped only on certain types of nodes.

only\_if: "'oracle' in $group\_names"

Etc.

--Michael
