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?
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/ce9e9d2e-f476-4294-a625-b1c0b6db4e5b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.