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.

139 lines
3.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. when: ansible_os_family != "CoreOS"
  12. - name: target temporary resolvconf cloud init file
  13. set_fact:
  14. resolvconffile: /tmp/resolveconf_cloud_init_conf
  15. when: ansible_os_family == "CoreOS"
  16. - name: create temporary resolveconf cloud init file
  17. command: cp -f /etc/resolv.conf "{{ resolvconffile }}"
  18. when: ansible_os_family == "CoreOS"
  19. - name: generate search domains to resolvconf
  20. set_fact:
  21. searchentries:
  22. "{{ ([ 'default.svc.' + dns_domain, 'svc.' + dns_domain ] + searchdomains|default([])) | join(' ') }}"
  23. - name: pick dnsmasq cluster IP
  24. set_fact:
  25. dnsmasq_server: >-
  26. {%- if skip_dnsmasq|bool -%}{{ [ skydns_server ] + upstream_dns_servers|default([]) }}{%- else -%}{{ [ dns_server ] }}{%- endif -%}
  27. - name: generate nameservers to resolvconf
  28. set_fact:
  29. nameserverentries:
  30. "{{ dnsmasq_server|default([]) + nameservers|default([]) }}"
  31. - name: Remove search and nameserver options from resolvconf head
  32. lineinfile:
  33. dest: /etc/resolvconf/resolv.conf.d/head
  34. state: absent
  35. regexp: "^{{ item }}.*$"
  36. backup: yes
  37. follow: yes
  38. with_items:
  39. - search
  40. - nameserver
  41. when: resolvconf.rc == 0
  42. notify: Dnsmasq | update resolvconf
  43. - name: Remove search and nameserver options from resolvconf cloud init temporary file
  44. lineinfile:
  45. dest: "{{resolvconffile}}"
  46. state: absent
  47. regexp: "^{{ item }}.*$"
  48. backup: yes
  49. follow: yes
  50. with_items:
  51. - search
  52. - nameserver
  53. when: ansible_os_family == "CoreOS"
  54. notify: Dnsmasq | update resolvconf for CoreOS
  55. - name: Add search domains to resolvconf file
  56. lineinfile:
  57. line: "search {{searchentries}}"
  58. dest: "{{resolvconffile}}"
  59. state: present
  60. insertbefore: BOF
  61. backup: yes
  62. follow: yes
  63. notify: Dnsmasq | update resolvconf
  64. - name: Add nameservers to resolv.conf
  65. blockinfile:
  66. dest: "{{resolvconffile}}"
  67. block: |-
  68. {% for item in nameserverentries -%}
  69. nameserver {{ item }}
  70. {% endfor %}
  71. state: present
  72. insertafter: "^search default.svc.*$"
  73. create: yes
  74. backup: yes
  75. follow: yes
  76. marker: "# Ansible nameservers {mark}"
  77. notify: Dnsmasq | update resolvconf
  78. - name: Add options to resolv.conf
  79. lineinfile:
  80. line: options {{ item }}
  81. dest: "{{resolvconffile}}"
  82. state: present
  83. regexp: "^options.*{{ item }}$"
  84. insertafter: EOF
  85. backup: yes
  86. follow: yes
  87. with_items:
  88. - ndots:{{ ndots }}
  89. - timeout:2
  90. - attempts:2
  91. notify: Dnsmasq | update resolvconf
  92. - name: Remove search and nameserver options from resolvconf base
  93. lineinfile:
  94. dest: /etc/resolvconf/resolv.conf.d/base
  95. state: absent
  96. regexp: "^{{ item }}.*$"
  97. backup: yes
  98. follow: yes
  99. with_items:
  100. - search
  101. - nameserver
  102. when: resolvconf.rc == 0
  103. notify: Dnsmasq | update resolvconf
  104. - name: disable resolv.conf modification by dhclient
  105. copy: src=dhclient_nodnsupdate dest=/etc/dhcp/dhclient-enter-hooks.d/znodnsupdate mode=0755
  106. notify: Dnsmasq | restart network
  107. when: ansible_os_family == "Debian"
  108. - name: disable resolv.conf modification by dhclient
  109. copy: src=dhclient_nodnsupdate dest=/etc/dhcp/dhclient.d/nodnsupdate mode=u+x
  110. notify: Dnsmasq | restart network
  111. when: ansible_os_family == "RedHat"
  112. - name: get temporary resolveconf cloud init file content
  113. command: cat {{ resolvconffile }}
  114. register: cloud_config
  115. when: ansible_os_family == "CoreOS"
  116. - name: persist resolvconf cloud init file
  117. template:
  118. dest: "{{resolveconf_cloud_init_conf}}"
  119. src: resolvconf.j2
  120. owner: root
  121. mode: 0644
  122. notify: Dnsmasq | update resolvconf for CoreOS
  123. when: ansible_os_family == "CoreOS"