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.

114 lines
3.1 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-master'][0]
  51. - name: check resolvconf
  52. stat: path=/etc/resolvconf/resolv.conf.d/head
  53. register: resolvconf
  54. - name: target resolv.conf file
  55. set_fact:
  56. resolvconffile: >-
  57. {%- if resolvconf.stat.exists == True -%}/etc/resolvconf/resolv.conf.d/head{%- else -%}/etc/resolv.conf{%- endif -%}
  58. - name: Add search resolv.conf
  59. lineinfile:
  60. line: "search {{ [ 'default.svc.' + dns_domain, 'svc.' + dns_domain, dns_domain ] | join(' ') }}"
  61. dest: "{{resolvconffile}}"
  62. state: present
  63. insertbefore: BOF
  64. backup: yes
  65. follow: yes
  66. - name: Add local dnsmasq to resolv.conf
  67. lineinfile:
  68. line: "nameserver {{dns_server}}"
  69. dest: "{{resolvconffile}}"
  70. state: present
  71. insertafter: "^search.*$"
  72. backup: yes
  73. follow: yes
  74. - name: Add options to resolv.conf
  75. lineinfile:
  76. line: options {{ item }}
  77. dest: "{{resolvconffile}}"
  78. state: present
  79. regexp: "^options.*{{ item }}$"
  80. insertafter: EOF
  81. backup: yes
  82. follow: yes
  83. with_items:
  84. - timeout:2
  85. - attempts:2
  86. - name: disable resolv.conf modification by dhclient
  87. copy: src=dhclient_nodnsupdate dest=/etc/dhcp/dhclient-enter-hooks.d/nodnsupdate mode=0755 backup=yes
  88. when: ansible_os_family == "Debian"
  89. - name: disable resolv.conf modification by dhclient
  90. copy: src=dhclient_nodnsupdate dest=/etc/dhcp/dhclient.d/nodnsupdate mode=u+x backup=yes
  91. when: ansible_os_family == "RedHat"
  92. - name: update resolvconf
  93. command: resolvconf -u
  94. changed_when: False
  95. when: resolvconf.stat.exists == True
  96. - meta: flush_handlers