-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdnsmasq_home.yml
129 lines (111 loc) · 2.89 KB
/
dnsmasq_home.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# This play enables dnsmasq DNS cache. Put /etc/hosts
# entries into /etc/dnsmasq.d/
#
# Not detect root servers:
#
# --extra-vars "nodetect=yes"
#
# Use dnsmasq for /etc/hosts
# --extra-vars "usehosts=no"
#
---
- hosts: all
vars:
nodetect: "no"
usehosts: "yes"
vars_files:
- networks.yml
tasks:
### REDHAT
# - name: Install dnsmasq packages
# yum: name=$item state=installed
# with_items:
# - dnsmasq
# - dnsmasq-utils
# - bind-utils
# tags:
# - packages
- name: Install dnsmasq
yum: name=dnsmasq
state=installed
when: ansible_os_family == "RedHat"
tags:
- packages
- name: Install dnsmasq-utils
yum: name=dnsmasq-utils
state=installed
when: ansible_os_family == "RedHat"
tags:
- packages
- name: Install bind-utils
yum: name=bind-utils
state=installed
when: ansible_os_family == "RedHat"
tags:
- packages
### DEBIAN
- name: Install dnsmasq
apt: name=dnsmasq
state=installed
when: ansible_os_family == "Debian"
tags:
- packages
- name: Install bind9utils
apt: name=bind9utils
state=installed
when: ansible_os_family == "Debian"
tags:
- packages
### CONFIGURATION
- name: Enable /etc/dnsmasq.d
lineinfile: dest=/etc/dnsmasq.conf
regexp='^conf-dir.*'
insertafter='^#conf-dir.*'
line='conf-dir=/etc/dnsmasq.d'
backup=yes
notify:
- Restart dnsmasq
tags:
- configs
- name: Create hosts.d directory
file: path=/etc/hosts.d
owner=root
group=root
state=directory
tags:
- hosts
- name: Enable /etc/hosts.d
lineinfile: dest=/etc/dnsmasq.conf
regexp='^addn-hosts.*'
insertafter='^#addn-hosts.*'
line='addn-hosts=/etc/hosts.d'
backup=yes
notify:
- Restart dnsmasq
tags:
- hosts
- name: Localhost DNS in /etc/resolv.conf
lineinfile: dest=/etc/resolv.conf
regexp='^nameserver 127.0.0.1'
insertbefore='^nameserver.*'
line='nameserver 127.0.0.1'
backup=yes
tags:
- resolv
- name: Localhost DNS for DHCP (${interfaces.home})
template: src=etc/dhcp/dhclient.conf.j2
dest=/etc/dhcp/dhclient-${interfaces.home}.conf
owner=root
group=root
backup=yes
when_string: "'${interfaces.home}' != ''"
tags:
- dhcp
- name: Start dnsmasq
service: name=dnsmasq
state=started
enabled=yes
handlers:
- name: Restart dnsmasq
service: name=dnsmasq
state=restarted