Skip to content

Instantly share code, notes, and snippets.

@sevkin
Last active February 13, 2017 13:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sevkin/b38c28bf86062f5f35bc053b70933009 to your computer and use it in GitHub Desktop.
Save sevkin/b38c28bf86062f5f35bc053b70933009 to your computer and use it in GitHub Desktop.
Install standalone dnsmasq instead of NetworkManager controlled - ansible playbook - ubuntu 16.04
---
- hosts: localhost
connection: local
# gather_facts: no
become: yes
vars:
- interfaces: ["lo", "docker0"]
tasks:
- name: install dnsmasq
apt: name=dnsmasq
- name: disable NM dnsmasq
ini_file: dest=/etc/NetworkManager/NetworkManager.conf
backup=yes
no_extra_spaces=yes
section=main
option=dns
value=dnsmasq
state=absent
register: nm
- name: nm update
shell: systemctl restart network-manager
when: nm.changed
- name: kill nm-dnsmasq
# nm-dnsmasq not sutdown when network-manager restart
shell: killall dnsmasq
when: nm.changed
- name: dnsmasq interfaces
template: src=./interface.conf.j2
dest=/etc/dnsmasq.d/interface.conf
mode=0644 owner=root group=root
- name: customize dnsmasq.service
# TODO always changed ?
copy: src=/lib/systemd/system/dnsmasq.service dest=/etc/systemd/system/dnsmasq.service
register: dnsmasq
- name: docker deps
ini_file: dest=/etc/systemd/system/dnsmasq.service
backup=yes
no_extra_spaces=yes
section=Unit
option=Requires
value="network.target docker.service"
state=present
register: systemctl
when: dnsmasq.changed
notify: restart dnsmasq
- name: systemctl daemon-reload
shell: systemctl daemon-reload
when: systemctl.changed
- name: docker deps 2
ini_file: dest=/etc/systemd/system/dnsmasq.service
backup=yes
no_extra_spaces=yes
section=Unit
option=After
value=docker.service
state=present
when: dnsmasq.changed
notify: restart dnsmasq
- name: standalone dnsmasq daemon
service: name=dnsmasq enabled=yes state=started
handlers:
- name: restart dnsmasq
shell: systemctl restart dnsmasq
{% for interface in interfaces %}
interface={{interface}}
{% endfor %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment