Skip to content

Instantly share code, notes, and snippets.

@zeridon
Created February 4, 2021 12:44
Show Gist options
  • Save zeridon/dfa57c5c14ce70112e02587bfff03431 to your computer and use it in GitHub Desktop.
Save zeridon/dfa57c5c14ce70112e02587bfff03431 to your computer and use it in GitHub Desktop.
ansible add all hosts in dnsmasq for resolving (delegate to dns servers)
- hosts: all
tasks:
- name: Add the inventory into dnsmasq
lineinfile:
dest: /etc/dnsmasq.d/40-custom-hosts.conf
regexp: '^host-record={{ item }}.*'
line: "host-record={{item}},{{ hostvars[item]['ansible_default_ipv4']['address'] }},,300"
state: present
when: (hostvars[item] is defined) and (hostvars[item]['ansible_default_ipv4'] is defined) and (hostvars[item]['ansible_default_ipv4']['address'] is defined)
with_items:
- "{{ groups['all'] }}"
delegate_to: "{{ item }}"
loop: ns01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment