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.

100 lines
2.7 KiB

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