Browse Source

Merge pull request #419 from bogdando/fix_322

Fix resolv.conf search/nameserver
pull/422/head
Smaine Kahlouch 8 years ago
committed by GitHub
parent
commit
36b6ae9a3c
3 changed files with 37 additions and 4 deletions
  1. 12
      roles/dnsmasq/defaults/main.yml
  2. 10
      roles/dnsmasq/handlers/main.yml
  3. 19
      roles/dnsmasq/tasks/main.yml

12
roles/dnsmasq/defaults/main.yml

@ -0,0 +1,12 @@
---
# Existing search/nameserver resolvconf entries will be purged and
# ensured by this additional data:
# Max of 4 names is allowed and no more than 256 - 17 chars total
# (a 2 is reserved for the 'default.svc.' and'svc.')
#searchdomains:
# - foo.bar.lc
# Max of 2 is allowed here (a 1 is reserved for the dns_server)
#nameservers:
# - 127.0.0.1

10
roles/dnsmasq/handlers/main.yml

@ -0,0 +1,10 @@
- name: Dnsmasq | restart network
service:
name: >-
{% if ansible_os_family == "RedHat" -%}
network
{%- elif ansible_os_family == "Debian" -%}
networking
{%- endif %}
state: restarted
when: ansible_os_family != "CoreOS"

19
roles/dnsmasq/tasks/main.yml

@ -68,9 +68,17 @@
resolvconffile: >- resolvconffile: >-
{%- if resolvconf.rc == 0 -%}/etc/resolvconf/resolv.conf.d/head{%- else -%}/etc/resolv.conf{%- endif -%} {%- if resolvconf.rc == 0 -%}/etc/resolvconf/resolv.conf.d/head{%- else -%}/etc/resolv.conf{%- endif -%}
- name: generate search domains to resolvconf
set_fact:
searchentries="{{ ([ 'default.svc.' + dns_domain, 'svc.' + dns_domain ] + searchdomains|default([])) | join(' ') }}"
- name: generate nameservers to resolvconf
set_fact:
nameserverentries="{{ nameservers|default([]) + [ dns_server ] }}"
- name: Add search resolv.conf - name: Add search resolv.conf
lineinfile: lineinfile:
line: "search {{ [ 'default.svc.' + dns_domain, 'svc.' + dns_domain, dns_domain ] | join(' ') }}"
line: "search {{searchentries}}"
dest: "{{resolvconffile}}" dest: "{{resolvconffile}}"
state: present state: present
insertbefore: BOF insertbefore: BOF
@ -79,12 +87,13 @@
- name: Add local dnsmasq to resolv.conf - name: Add local dnsmasq to resolv.conf
lineinfile: lineinfile:
line: "nameserver {{dns_server}}"
line: "nameserver {{item}}"
dest: "{{resolvconffile}}" dest: "{{resolvconffile}}"
state: present state: present
insertafter: "^search.*$" insertafter: "^search.*$"
backup: yes backup: yes
follow: yes follow: yes
with_items: "{{nameserverentries}}"
- name: Add options to resolv.conf - name: Add options to resolv.conf
lineinfile: lineinfile:
@ -100,11 +109,13 @@
- attempts:2 - attempts:2
- name: disable resolv.conf modification by dhclient - name: disable resolv.conf modification by dhclient
copy: src=dhclient_nodnsupdate dest=/etc/dhcp/dhclient-enter-hooks.d/nodnsupdate mode=0755 backup=yes
copy: src=dhclient_nodnsupdate dest=/etc/dhcp/dhclient-enter-hooks.d/znodnsupdate mode=0755 backup=yes
notify: Dnsmasq | restart network
when: ansible_os_family == "Debian" when: ansible_os_family == "Debian"
- name: disable resolv.conf modification by dhclient - name: disable resolv.conf modification by dhclient
copy: src=dhclient_nodnsupdate dest=/etc/dhcp/dhclient.d/nodnsupdate mode=u+x backup=yes
copy: src=dhclient_nodnsupdate dest=/etc/dhcp/dhclient.d/znodnsupdate mode=u+x backup=yes
notify: Dnsmasq | restart network
when: ansible_os_family == "RedHat" when: ansible_os_family == "RedHat"
- name: update resolvconf - name: update resolvconf

Loading…
Cancel
Save