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?