# test host for group membership

**URL:** <https://forum.ansible.com/t/test-host-for-group-membership/12024>\
**Category:** Ansible Project\
**Tags:** ansible-project\
**Created:** [October 24, 2012, 12:30pm UTC](https://forum.ansible.com/t/test-host-for-group-membership/12024 "2012-10-24T12:30:40Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jeroen\_Hoekx](https://avatars.discourse-cdn.com/v4/letter/j/ba9def/32.png) [@Jeroen\_Hoekx](https://forum.ansible.com/u/Jeroen_Hoekx)\
**Post date:** [October 24, 2012, 12:30pm UTC](https://forum.ansible.com/t/test-host-for-group-membership/12024/1 "2012-10-24T12:30:40Z")

</div>

My approach is totally different than what Michael proposes 🙂

In this case, I would have a per group 'nameservers' list variable in  
your inventory. Use a for loop in the jinja template like:  
{% for server in nameservers %}  
nameserver {{ server }}  
{% endfor %}

There are cases where this approach is not desirable. In that case you  
can have the logic in the template:  
{% if 'virt-managed' in group\_names %}  
do one thing  
{% else %}  
do the other thing  
{% endif %}

I generally use the first approach. I use the second approach when all  
systems except a few ones need the same configuration.

I don't want too much logic in my playbooks.

Greetings,

Jeroen
