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.

93 lines
2.9 KiB

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. tags: bootstrap-os
  7. - name: ensure dnsmasq.d-available directory exists
  8. file:
  9. path: /etc/dnsmasq.d-available
  10. state: directory
  11. tags: bootstrap-os
  12. - name: check system nameservers
  13. shell: awk '/^nameserver/ {print $NF}' /etc/resolv.conf
  14. changed_when: False
  15. register: system_nameservers
  16. - name: init system_and_upstream_dns_servers
  17. set_fact:
  18. system_and_upstream_dns_servers: "{{ upstream_dns_servers|default([]) }}"
  19. - name: combine upstream_dns_servers and system nameservers (only for docker_dns)
  20. set_fact:
  21. system_and_upstream_dns_servers: "{{ system_and_upstream_dns_servers | union(system_nameservers.stdout_lines) | unique }}"
  22. when: system_nameservers.stdout != "" and resolvconf_mode != 'host_resolvconf'
  23. - name: Write dnsmasq configuration
  24. template:
  25. src: 01-kube-dns.conf.j2
  26. dest: /etc/dnsmasq.d-available/01-kube-dns.conf
  27. mode: 0755
  28. backup: yes
  29. register: dnsmasq_config
  30. - name: Stat dnsmasq configuration
  31. stat: path=/etc/dnsmasq.d/01-kube-dns.conf
  32. register: sym
  33. - name: Move previous configuration
  34. command: mv /etc/dnsmasq.d/01-kube-dns.conf /etc/dnsmasq.d-available/01-kube-dns.conf.bak
  35. changed_when: False
  36. when: sym.stat.islnk is defined and sym.stat.islnk == False
  37. - name: Enable dnsmasq configuration
  38. file:
  39. src: /etc/dnsmasq.d-available/01-kube-dns.conf
  40. dest: /etc/dnsmasq.d/01-kube-dns.conf
  41. state: link
  42. - name: Create dnsmasq manifests
  43. template: src={{item.file}} dest={{kube_config_dir}}/{{item.file}}
  44. with_items:
  45. - {file: dnsmasq-ds.yml, type: ds}
  46. - {file: dnsmasq-svc.yml, type: svc}
  47. register: manifests
  48. when: inventory_hostname == groups['kube-master'][0]
  49. #FIXME: remove manifests.changed condition if kubernetes/features#124 is implemented
  50. - name: Delete existing dnsmasq daemonset
  51. kube:
  52. name: dnsmasq
  53. namespace: "{{system_namespace}}"
  54. kubectl: "{{bin_dir}}/kubectl"
  55. resource: "{{item.item.type}}"
  56. filename: "{{kube_config_dir}}/{{item.item.file}}"
  57. kubectl: "{{ bin_dir }}/kubectl"
  58. filename: "{{ kube_config_dir }}/weave-net.yml"
  59. resource: "ds"
  60. namespace: "{{system_namespace}}"
  61. state: absent
  62. with_items: "{{ manifests.results }}"
  63. when: inventory_hostname == groups['kube-master'][0] and item.item.type == "ds" and (manifests.changed or dnsmasq_config.changed)
  64. - name: Start Resources
  65. kube:
  66. name: dnsmasq
  67. namespace: "{{system_namespace}}"
  68. kubectl: "{{bin_dir}}/kubectl"
  69. resource: "{{item.item.type}}"
  70. filename: "{{kube_config_dir}}/{{item.item.file}}"
  71. state: "{{item.changed | ternary('latest','present') }}"
  72. with_items: "{{ manifests.results }}"
  73. when: inventory_hostname == groups['kube-master'][0]
  74. - name: Check for dnsmasq port (pulling image and running container)
  75. wait_for:
  76. host: "{{dns_server}}"
  77. port: 53
  78. delay: 5
  79. when: inventory_hostname == groups['kube-node'][0]
  80. tags: facts