# all in inventory does not resolve in template

**URL:** <https://forum.ansible.com/t/all-in-inventory-does-not-resolve-in-template/20516>\
**Category:** Ansible Project\
**Created:** [February 10, 2016, 4:10pm UTC](https://forum.ansible.com/t/all-in-inventory-does-not-resolve-in-template/20516 "2016-02-10T16:10:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jepper](https://avatars.discourse-cdn.com/v4/letter/j/49beb7/32.png) [@jepper](https://forum.ansible.com/u/jepper)\
**Post date:** [February 10, 2016, 4:10pm UTC](https://forum.ansible.com/t/all-in-inventory-does-not-resolve-in-template/20516/1 "2016-02-10T16:10:55Z")

</div>

I am doing this in a template to generate /etc/hosts

{% for item in groups[‘all’] %}  
{{ hostvars[item][‘ansible\_ssh\_host’] }} {{ item }}  
{% endfor %}

My inventory looks like this:

[emmaxd:children]  
application\_servers  
utility\_servers  
postgres\_master  
alfresco\_application

alfresco\_database  
alfresco\_storage

[application\_servers]  
apbe01 host\_alias=apbe01 ansible\_ssh\_host=10.124.1.1

[utility\_servers]  
apbe01

[postgres\_master]  
apbe01

[alfresco\_application]  
apbe02 host\_alias=apbe02 ansible\_ssh\_host=10.124.1.2

[alfresco\_database]  
apbe02

[alfresco\_storage]  
apbe02

If I replace groups[‘all’] with groups[‘emmaxd’] it works. If I don’t, this error:

fatal: [emmaxdapbe01] =\> {‘msg’: “AnsibleUndefinedVariable: One or more undefined variables: ‘dict object’ has no attribute ‘ansible\_ssh\_host’”, ‘failed’: True}  
fatal: [emmaxdapbe01] =\> {‘msg’: “AnsibleUndefinedVariable: One or more undefined variables: ‘dict object’ has no attribute ‘ansible\_ssh\_host’”, ‘failed’: True}

Why does it not resolve [‘all’] to every machine in the inventory?

---

<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:** [February 10, 2016, 4:27pm UTC](https://forum.ansible.com/t/all-in-inventory-does-not-resolve-in-template/20516/2 "2016-02-10T16:27:21Z")

</div>

First,do NOT use item as it overloads the existing variable from loops

The error you are getting is because not all hosts have ansible\_ssh\_host defined but all those in emmaxd group do

---

<div class="post-metadata">

**Author:** ![jepper](https://avatars.discourse-cdn.com/v4/letter/j/49beb7/32.png) [@jepper](https://forum.ansible.com/u/jepper)\
**Post date:** [February 10, 2016, 5:57pm UTC](https://forum.ansible.com/t/all-in-inventory-does-not-resolve-in-template/20516/3 "2016-02-10T17:57:52Z")

</div>

Good point about item! Would it be better to declare the inventory like this?

[emmaxd]

apbe01 host\_alias=apbe01 ansible\_ssh\_host=10.124.1.1

apbe02 host\_alias=apbe02 ansible\_ssh\_host=10.124.1.2

[application\_servers]  
apbe01

[utility\_servers]  
apbe01

[postgres\_master]  
apbe01

[alfresco\_application]  
apbe02

[alfresco\_database]  
apbe02

[alfresco\_storage]  
apbe02

---

<div class="post-metadata">

**Author:** ![jepper](https://avatars.discourse-cdn.com/v4/letter/j/49beb7/32.png) [@jepper](https://forum.ansible.com/u/jepper)\
**Post date:** [February 10, 2016, 6:07pm UTC](https://forum.ansible.com/t/all-in-inventory-does-not-resolve-in-template/20516/4 "2016-02-10T18:07:29Z")

</div>

This made no difference. I’m confused as to how to use [‘all’]. Am I making bad choices in how I organise the inventory?

---

<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:** [February 10, 2016, 6:37pm UTC](https://forum.ansible.com/t/all-in-inventory-does-not-resolve-in-template/20516/5 "2016-02-10T18:37:26Z")

</div>

check:

ansible -m debug -a “msg={{ansible\_ssh\_host|default(‘MISSING’)}}” all -i /path/to/your/inventory

---

<div class="post-metadata">

**Author:** ![jepper](https://avatars.discourse-cdn.com/v4/letter/j/49beb7/32.png) [@jepper](https://forum.ansible.com/u/jepper)\
**Post date:** [February 11, 2016, 12:03am UTC](https://forum.ansible.com/t/all-in-inventory-does-not-resolve-in-template/20516/6 "2016-02-11T00:03:16Z")

</div>

Brilliant. Found the problem. Somehow “—” had made into the inventory.
