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.

131 lines
3.5 KiB

9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
  1. ---
  2. - name: ensure dnsmasq.d directory exists
  3. file:
  4. path: /etc/dnsmasq.d
  5. state: directory
  6. - name: ensure dnsmasq.d-available directory exists
  7. file:
  8. path: /etc/dnsmasq.d-available
  9. state: directory
  10. - name: Write dnsmasq configuration
  11. template:
  12. src: 01-kube-dns.conf.j2
  13. dest: /etc/dnsmasq.d-available/01-kube-dns.conf
  14. mode: 0755
  15. backup: yes
  16. - name: Stat dnsmasq configuration
  17. stat: path=/etc/dnsmasq.d/01-kube-dns.conf
  18. register: sym
  19. - name: Move previous configuration
  20. command: mv /etc/dnsmasq.d/01-kube-dns.conf /etc/dnsmasq.d-available/01-kube-dns.conf.bak
  21. changed_when: False
  22. when: sym.stat.islnk is defined and sym.stat.islnk == False
  23. - name: Enable dnsmasq configuration
  24. file:
  25. src: /etc/dnsmasq.d-available/01-kube-dns.conf
  26. dest: /etc/dnsmasq.d/01-kube-dns.conf
  27. state: link
  28. - name: Create dnsmasq manifests
  29. template: src={{item.file}} dest=/etc/kubernetes/{{item.file}}
  30. with_items:
  31. - {file: dnsmasq-ds.yml, type: ds}
  32. - {file: dnsmasq-svc.yml, type: svc}
  33. register: manifests
  34. when: inventory_hostname == groups['kube-master'][0]
  35. - name: Start Resources
  36. kube:
  37. name: dnsmasq
  38. namespace: kube-system
  39. kubectl: "{{bin_dir}}/kubectl"
  40. resource: "{{item.item.type}}"
  41. filename: /etc/kubernetes/{{item.item.file}}
  42. state: "{{item.changed | ternary('latest','present') }}"
  43. with_items: "{{ manifests.results }}"
  44. when: inventory_hostname == groups['kube-master'][0]
  45. - name: Check for dnsmasq port (pulling image and running container)
  46. wait_for:
  47. host: "{{dns_server}}"
  48. port: 53
  49. delay: 5
  50. when: inventory_hostname == groups['kube-node'][0]
  51. - name: check resolvconf
  52. shell: which resolvconf
  53. register: resolvconf
  54. ignore_errors: yes
  55. - name: target resolv.conf file
  56. set_fact:
  57. resolvconffile: >-
  58. {%- if resolvconf.rc == 0 -%}/etc/resolvconf/resolv.conf.d/head{%- else -%}/etc/resolv.conf{%- endif -%}
  59. - name: generate search domains to resolvconf
  60. set_fact:
  61. searchentries="{{ ([ 'default.svc.' + dns_domain, 'svc.' + dns_domain ] + searchdomains|default([])) | join(' ') }}"
  62. - name: generate nameservers to resolvconf
  63. set_fact:
  64. nameserverentries="{{ nameservers|default([]) + [ dns_server ] }}"
  65. - name: Add search resolv.conf
  66. lineinfile:
  67. line: "search {{searchentries}}"
  68. dest: "{{resolvconffile}}"
  69. state: present
  70. insertbefore: BOF
  71. backup: yes
  72. follow: yes
  73. - name: Add local dnsmasq to resolv.conf
  74. lineinfile:
  75. line: "nameserver {{item}}"
  76. dest: "{{resolvconffile}}"
  77. state: present
  78. insertafter: "^search.*$"
  79. backup: yes
  80. follow: yes
  81. with_items: "{{nameserverentries}}"
  82. - name: Add options to resolv.conf
  83. lineinfile:
  84. line: options {{ item }}
  85. dest: "{{resolvconffile}}"
  86. state: present
  87. regexp: "^options.*{{ item }}$"
  88. insertafter: EOF
  89. backup: yes
  90. follow: yes
  91. with_items:
  92. - timeout:2
  93. - attempts:2
  94. - name: Remove search and nameserver options from resolvconf base
  95. lineinfile:
  96. dest: /etc/resolvconf/resolv.conf.d/base
  97. state: absent
  98. regexp: "^{{ item }}.*$"
  99. backup: yes
  100. follow: yes
  101. with_items:
  102. - search
  103. - nameserver
  104. when: resolvconf.rc == 0
  105. - name: disable resolv.conf modification by dhclient
  106. copy: src=dhclient_nodnsupdate dest=/etc/dhcp/dhclient-enter-hooks.d/znodnsupdate mode=0755
  107. notify: Dnsmasq | restart network
  108. when: ansible_os_family == "Debian"
  109. - name: disable resolv.conf modification by dhclient
  110. copy: src=dhclient_nodnsupdate dest=/etc/dhcp/dhclient.d/nodnsupdate mode=u+x
  111. notify: Dnsmasq | restart network
  112. when: ansible_os_family == "RedHat"