# Not sure why this when: is not working.

**URL:** <https://forum.ansible.com/t/not-sure-why-this-when-is-not-working/23031>\
**Category:** Ansible Project\
**Created:** [November 15, 2016, 3:53pm UTC](https://forum.ansible.com/t/not-sure-why-this-when-is-not-working/23031 "2016-11-15T15:53:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Steven\_Smith](https://avatars.discourse-cdn.com/v4/letter/s/8e8cbc/32.png) [@Steven\_Smith](https://forum.ansible.com/u/Steven_Smith)\
**Post date:** [November 15, 2016, 3:53pm UTC](https://forum.ansible.com/t/not-sure-why-this-when-is-not-working/23031/1 "2016-11-15T15:53:21Z")

</div>

This is the play I am trying to get to run:

- name: Install httpd  
yum: name=httpd state=latest disable\_gpg\_check=yes  
when: (inventory\_hostname in groups[“web”]) or (inventory\_hostname in groups[“web\_backend”])  
ignore\_errors: true  
notify: restart httpd

I get this error:

fatal: [rhel7]: FAILED! =\> {“failed”: true, “msg”: “The conditional check ‘(inventory\_hostname in groups["web"]) or (inventory\_hostname in groups["web\_backend"])’ failed. The error was: error while evaluating conditional ((inventory\_hostname in groups["web"]) or (inventory\_hostname in groups["web\_backend"])): Unable to look up a name or access an attribute in template string ({% if (inventory\_hostname in groups["web"]) or (inventory\_hostname in groups["web\_backend"]) %} True {% else %} False {% endif %}).\nMake sure your variable name does not contain invalid characters like ‘-’: argument of type ‘StrictUndefined’ is not iterable\n\nThe error appears to have been in ‘/etc/ansible/roles/httpd/tasks/enabled.yml’: line 14, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: Install httpd\n ^ here\n”}

If my hosts file has nothing at all for “web” or “web\_backend” I am hoping it would just skip over this entire play instead of throwing this big red error.

If either one of those are defined, then I want this play to run… can anyone please help?

---

<div class="post-metadata">

**Author:** ![Alexander\_H\_Laughlin](https://avatars.discourse-cdn.com/v4/letter/a/ce7236/32.png) [@Alexander\_H\_Laughlin](https://forum.ansible.com/u/Alexander_H_Laughlin)\
**Post date:** [November 16, 2016, 9:53pm UTC](https://forum.ansible.com/t/not-sure-why-this-when-is-not-working/23031/2 "2016-11-16T21:53:37Z")

</div>

`

---

<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:** [November 17, 2016, 12:44am UTC](https://forum.ansible.com/t/not-sure-why-this-when-is-not-working/23031/3 "2016-11-17T00:44:30Z")

</div>

This is wrong, when: are always templated and you should not use {{ }}, if what you say were true groups wouldn’t work either as they are also a variable. You are actually doing double interpolation, that is why you need the quotes.

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [November 17, 2016, 5:45am UTC](https://forum.ansible.com/t/not-sure-why-this-when-is-not-working/23031/4 "2016-11-17T05:45:12Z")

</div>

All variable that is not defined you'll need to filter through the default filter, try this.

when: (inventory\_hostname in groups["web"] | default()) or (inventory\_hostname in groups["web\_backend"] | default())
