---
- name: install dnsmasq and bind-utils
  sudo: yes
  yum:
    name: "{{ item }}"
    state: latest
  with_items:
    - dnsmasq
    - bind-utils
  tags:
    - package
    - dnsmasq

- name: configure consul lookups
  sudo: yes
  copy: 
    content: 'server=/consul/127.0.0.1#8600'
    dest: /etc/dnsmasq.d/10-consul
  notify:
    - restart dnsmasq
  tags:
    - dnsmasq

- name: set localhost as nameserver
  sudo: yes
  lineinfile:
    dest: /etc/resolv.conf
    line: "nameserver 127.0.0.1"
    insertbefore: "^nameserver"
  tags:
    - dnsmasq

---
- name: install dnsmasq and bind-utils
  sudo: yes
  yum:
    name: "{{ item }}"
    state: latest
  with_items:
    - dnsmasq
    - bind-utils
  tags:
    - dnsmasq

- name: configure dnsmasq for consul 
  sudo: yes
  template: 
    src: 10-consul 
    dest: /etc/NetworkManager/dnsmasq.d/10-consul
  tags:
    - dnsmasq

# Before we reboot the system, resolve IPs via consul
- name: configure dnsmasq symlink
  sudo: yes
  file:
    src: /etc/NetworkManager/dnsmasq.d/10-consul
    dest: /etc/dnsmasq.d/10-consul 
    state: link
  notify:
    - restart dnsmasq 
  tags:
    - dnsmasq 

- name: configure base dnsmasq 
  sudo: yes
  template:
    src: 90-base
    dest: /etc/NetworkManager/dnsmasq.d/90-base
  tags:
    - dnsmasq 

- name: configure networkmanager for dnsmasq
  sudo: yes
  lineinfile:
    dest: /etc/NetworkManager/NetworkManager.conf
    line: "dns=dnsmasq"
    insertbefore: "^plugins"
  notify:
    - disable dnsmasq
  tags:
    - dnsmasq

- name: set localhost as nameserver
  sudo: yes
  lineinfile:
    dest: /etc/resolv.conf
    line: "nameserver 127.0.0.1"
    insertafter: "^search"
  tags:
    - dnsmasq

Update dnsmasq config to be launched from NetworkManager
Update dnsmasq config to be launched from NetworkManager
