# Non-existing group resulted in error.

**URL:** <https://forum.ansible.com/t/non-existing-group-resulted-in-error/18941>\
**Category:** Ansible Project\
**Created:** [August 4, 2015, 8:44pm UTC](https://forum.ansible.com/t/non-existing-group-resulted-in-error/18941 "2015-08-04T20:44:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nico\_K](https://avatars.discourse-cdn.com/v4/letter/n/46a35a/32.png) [@Nico\_K](https://forum.ansible.com/u/Nico_K)\
**Post date:** [August 4, 2015, 8:44pm UTC](https://forum.ansible.com/t/non-existing-group-resulted-in-error/18941/1 "2015-08-04T20:44:49Z")

</div>

- name: task  
debug: msg=“I will fail”  
when: inventory\_hostname in groups[‘doesnotexist’]

fatal: [host] =\> error while evaluating conditional: inventory\_hostname in groups[‘doesnotexist’]

I’m assuming this is not expected behavior? Running Ansible 1.9.2, if it’s not, I’ll be happy to file a bug.

Regards,  
Nico

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [August 4, 2015, 8:59pm UTC](https://forum.ansible.com/t/non-existing-group-resulted-in-error/18941/2 "2015-08-04T20:59:58Z")

</div>

I for one expect it to fail, what were you expecting?

---

<div class="post-metadata">

**Author:** ![Nico\_K](https://avatars.discourse-cdn.com/v4/letter/n/46a35a/32.png) [@Nico\_K](https://forum.ansible.com/u/Nico_K)\
**Post date:** [August 5, 2015, 5:35am UTC](https://forum.ansible.com/t/non-existing-group-resulted-in-error/18941/3 "2015-08-05T05:35:27Z")

</div>

It to ignore the fact that this group doesn’t exist within this playbook/inventory for the sake of re-usability of the role.

---

<div class="post-metadata">

**Author:** ![R\_Dikkes](https://avatars.discourse-cdn.com/v4/letter/r/7ba0ec/32.png) [@R\_Dikkes](https://forum.ansible.com/u/R_Dikkes)\
**Post date:** [August 5, 2015, 1:25pm UTC](https://forum.ansible.com/t/non-existing-group-resulted-in-error/18941/4 "2015-08-05T13:25:31Z")

</div>

Maybe you could look at ignore\_error ?

---

<div class="post-metadata">

**Author:** ![Nico\_K](https://avatars.discourse-cdn.com/v4/letter/n/46a35a/32.png) [@Nico\_K](https://forum.ansible.com/u/Nico_K)\
**Post date:** [August 17, 2015, 1:38pm UTC](https://forum.ansible.com/t/non-existing-group-resulted-in-error/18941/5 "2015-08-17T13:38:12Z")

</div>

Ignoring errors is hardly ever the correct way of dealing with things.

Anyway, for those interested, the obvious fix is to check whether the group you are looking for is in the current list of groups instead of checking whether the nodename is in a specific group, so instead of:

inventory\_hostname in groups

do a

x in group\_names
