I have a template to build /etc/hosts by taking stuff from the inventory
file. It's fragile to be sure, and I'm looking for suggestions. Here what I
have so far:
$ cat hosts.j2
127.0.0.1 localhost localhost.localdomain localhost4
localhost4.localdomain4
{% for host in groups['all'] %}
{{ hostvars[host]['ansible_eth0']['ipv4']['address'] }} {{ host }} {{ host
}}.{{ clientspecific_dns_domain }}
{% endfor %}
This generates
$ cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4
localhost4.localdomain4
10.124.44.2 box1 box1.domain.com
10.124.44.3 box2 box2.domain.com
The problem with this is if I change the scope of targets, e.g.
ansible-playbook site.yml -l box1
I end with just box1 in the hosts file on box1. Is there a better way?
--
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/89d4e8d3-295d-41ff-86f3-b6a319ea1ef9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.