You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

102 lines
2.8 KiB

  1. ---
  2. - name: check resolvconf
  3. shell: which resolvconf
  4. register: resolvconf
  5. ignore_errors: yes
  6. changed_when: false
  7. - name: target resolv.conf file
  8. set_fact:
  9. resolvconffile: >-
  10. {%- if resolvconf.rc == 0 -%}/etc/resolvconf/resolv.conf.d/head{%- else -%}/etc/resolv.conf{%- endif -%}
  11. - name: generate search domains to resolvconf
  12. set_fact:
  13. searchentries:
  14. "{{ ([ 'default.svc.' + dns_domain, 'svc.' + dns_domain ] + searchdomains|default([])) | join(' ') }}"
  15. - name: pick dnsmasq cluster IP
  16. set_fact:
  17. dnsmasq_server: >-
  18. {%- if skip_dnsmasq|bool -%}{{ [ skydns_server ] + upstream_dns_servers|default([]) }}{%- else -%}{{ [ dns_server ] }}{%- endif -%}
  19. - name: generate nameservers to resolvconf
  20. set_fact:
  21. nameserverentries:
  22. "{{ dnsmasq_server|default([]) + nameservers|default([]) }}"
  23. - name: Remove search and nameserver options from resolvconf head
  24. lineinfile:
  25. dest: /etc/resolvconf/resolv.conf.d/head
  26. state: absent
  27. regexp: "^{{ item }}.*$"
  28. backup: yes
  29. follow: yes
  30. with_items:
  31. - search
  32. - nameserver
  33. when: resolvconf.rc == 0
  34. notify: Dnsmasq | update resolvconf
  35. - name: Add search domains to resolv.conf
  36. lineinfile:
  37. line: "search {{searchentries}}"
  38. dest: "{{resolvconffile}}"
  39. state: present
  40. insertbefore: BOF
  41. backup: yes
  42. follow: yes
  43. notify: Dnsmasq | update resolvconf
  44. - name: Add nameservers to resolv.conf
  45. blockinfile:
  46. dest: "{{resolvconffile}}"
  47. block: |-
  48. {% for item in nameserverentries -%}
  49. nameserver {{ item }}
  50. {% endfor %}
  51. state: present
  52. insertafter: "^search.*$"
  53. create: yes
  54. backup: yes
  55. follow: yes
  56. marker: "# Ansible nameservers {mark}"
  57. notify: Dnsmasq | update resolvconf
  58. - name: Add options to resolv.conf
  59. lineinfile:
  60. line: options {{ item }}
  61. dest: "{{resolvconffile}}"
  62. state: present
  63. regexp: "^options.*{{ item }}$"
  64. insertafter: EOF
  65. backup: yes
  66. follow: yes
  67. with_items:
  68. - ndots:{{ ndots }}
  69. - timeout:2
  70. - attempts:2
  71. notify: Dnsmasq | update resolvconf
  72. - name: Remove search and nameserver options from resolvconf base
  73. lineinfile:
  74. dest: /etc/resolvconf/resolv.conf.d/base
  75. state: absent
  76. regexp: "^{{ item }}.*$"
  77. backup: yes
  78. follow: yes
  79. with_items:
  80. - search
  81. - nameserver
  82. when: resolvconf.rc == 0
  83. notify: Dnsmasq | update resolvconf
  84. - name: disable resolv.conf modification by dhclient
  85. copy: src=dhclient_nodnsupdate dest=/etc/dhcp/dhclient-enter-hooks.d/znodnsupdate mode=0755
  86. notify: Dnsmasq | restart network
  87. when: ansible_os_family == "Debian"
  88. - name: disable resolv.conf modification by dhclient
  89. copy: src=dhclient_nodnsupdate dest=/etc/dhcp/dhclient.d/nodnsupdate mode=u+x
  90. notify: Dnsmasq | restart network
  91. when: ansible_os_family == "RedHat"