# " Unable to look up a name or access an attribute in template string" when use conditional check

**URL:** <https://forum.ansible.com/t/unable-to-look-up-a-name-or-access-an-attribute-in-template-string-when-use-conditional-check/25086>\
**Category:** Ansible Project\
**Created:** [July 25, 2017, 9:48pm UTC](https://forum.ansible.com/t/unable-to-look-up-a-name-or-access-an-attribute-in-template-string-when-use-conditional-check/25086 "2017-07-25T21:48:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![G\_Muirdok](https://avatars.discourse-cdn.com/v4/letter/g/aeb1de/32.png) [@G\_Muirdok](https://forum.ansible.com/u/G_Muirdok)\
**Post date:** [July 25, 2017, 9:48pm UTC](https://forum.ansible.com/t/unable-to-look-up-a-name-or-access-an-attribute-in-template-string-when-use-conditional-check/25086/1 "2017-07-25T21:48:33Z")

</div>

**Got error for every run after upgrade to** 2.3.1.0\*\*:\*\*

root@aaaaaaaaaansible:~/nexkek# ansible --version  
ansible 2.3.1.0  
config file = /root/nexkek/ansible.cfg  
configured module search path = Default w/o overrides  
python version = 2.7.6 (default, Oct 26 2016, 20:30:19) [GCC 4.8.4]

fatal: [192.168.1.36]: FAILED! =\> {  
“failed”: true,  
“msg”: “The conditional check ‘inventory\_hostname in groups.cent6local or inventory\_hostname in groups.cent7local or inventory\_hostname in groups.ubuntulocal’ failed. The error was: error while evaluating conditional (inventory\_hostname in groups.cent6local or inventory\_hostname in groups.cent7local or inventory\_hostname in groups.ubuntulocal): Unable to look up a name or access an attribute in template string ({% if inventory\_hostname in groups.cent6local or inventory\_hostname in groups.cent7local or inventory\_hostname in groups.ubuntulocal %} 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 ‘/root/nexkek/includes/io\_start.yml’: line 7, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n ignore\_errors: yes\n- debug: var=vdbench.stdout\_lines\n ^ here\n”  
}

**the include:**

- include: includes/io\_start.yml  
when: inventory\_hostname in groups.cent6local or inventory\_hostname in groups.cent7local or

inventory\_hostname in groups.ubuntulocal  
tags: [“io”,“io:start”,“io:start:local”]

# checked both variants -" when: inventory\_hostname in groups[‘cent6local’] or inventory\_hostname in groups[‘cent7local’] or inventory\_hostname in groups[‘ubuntulocal’] "

**includes/io\_start.yml is quite simple task:**

- name: Run vdb task  
shell: “{{ vdb\_folder\_path }}/{{ vdbshell }} -f {{ vdb\_folder\_path }}/{{ vdbench\_config }} -o {{ vdb\_output }}”  
async: 4000000  
poll: 0  
register: vdb  
ignore\_errors: yes
- debug: var=vdb.stdout\_lines

**inventory:**

[cent7local]  
192.168.1.86  
192.168.1.77

…

So the main question - how could I use the condition like:  
“inventory\_hostname in groups.cent6local or inventory\_hostname in groups.cent7local or inventory\_hostname in groups.ubuntulocal” ? Was it changed?

---

<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:** [July 26, 2017, 6:20am UTC](https://forum.ansible.com/t/unable-to-look-up-a-name-or-access-an-attribute-in-template-string-when-use-conditional-check/25086/2 "2017-07-26T06:20:21Z")

</div>

> \*Got error for every run after upgrade to \*2.3.1.0\*:\*
> 
> root@aaaaaaaaaansible:~/nexkek# ansible --version  
> ansible 2.3.1.0  
> &nbsp;&nbsp;&nbsp;config file = /root/nexkek/ansible.cfg  
> &nbsp;&nbsp;&nbsp;configured module search path = Default w/o overrides  
> &nbsp;&nbsp;&nbsp;python version = 2.7.6 (default, Oct 26 2016, 20:30:19) [GCC 4.8.4]
> 
> fatal: [192.168.1.36]: FAILED! =\> {  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"failed": true,  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"msg": "The conditional check 'inventory\_hostname in groups.cent6local  
> or inventory\_hostname in groups.cent7local or inventory\_hostname in  
> groups.ubuntulocal' failed. The error was: error while evaluating  
> conditional (inventory\_hostname in groups.cent6local or inventory\_hostname  
> in groups.cent7local or inventory\_hostname in groups.ubuntulocal): Unable  
> to look up a name or access an attribute in template string ({% if  
> inventory\_hostname in groups.cent6local or inventory\_hostname in  
> groups.cent7local or inventory\_hostname in groups.ubuntulocal %} 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  
> '/root/nexkek/includes/io\_start.yml': line 7, column 3, but may\nbe  
> elsewhere in the file depending on the exact syntax problem.\n\nThe  
> offending line appears to be:\n\n ignore\_errors: yes\n- debug:  
> var=vdbench.stdout\_lines\n ^ here\n"  
> }
> 
> \*the include:\*
> 
> &nbsp;&nbsp;&nbsp;- include: includes/io\_start.yml  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;when: inventory\_hostname in groups.cent6local or inventory\_hostname in  
> groups.cent7local or  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;inventory\_hostname in groups.ubuntulocal  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tags: ["io","io:start","io:start:local"]

I think this error message is because of one or more groups is not defined. Do you have all 3 groups in the inventory?

> \*inventory:\*
> 
> [cent7local]  
> 192.168.1.86  
> 192.168.1.77  
> ....

Here you only list one of the groups, your code need all 3 defined to work.  
If this is not the case you need to filter it with default()

> So the main question - how could I use the condition like:  
> "inventory\_hostname in groups.cent6local or inventory\_hostname in  
> groups.cent7local or inventory\_hostname in groups.ubuntulocal" ? Was it  
> changed?

The functionality have not changed. But newer Ansible is more restrictive, before it ignored some errors but newer version fails instead, since that's more sane.  
But a few error message is not that informative, but it's getting better.
