Ansible Inventory to DNS Config
Here’s a little snippet that will use your Ansible inventory to populate dnsmasq
domain to ip rules.
File: dns-server.yml
- template:
src: templates/austin-dns.j2
dest: /etc/dnsmasq.d/austin-dns.conf
become: yes
File: austin-dns.yml
{% for site_name, site in hostvars.iteritems() %}
address=/{{ site_name }}/{{ site['ansible_host'] }}
{% endfor %}
listen-address=192.168.1.220
Note, this will only work if you don’t directly reference your ip address in the inventory host name. You want your inventory to look like this:
[dev3]
dev3.lab ansible_host=192.168.1.111
[dev4]
dev4.lab ansible_host=192.168.1.112