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.

90 lines
2.8 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:
  32. path: /etc/dnsmasq.d/01-kube-dns.conf
  33. register: sym
  34. - name: Move previous configuration
  35. command: mv /etc/dnsmasq.d/01-kube-dns.conf /etc/dnsmasq.d-available/01-kube-dns.conf.bak
  36. changed_when: False
  37. when: sym.stat.islnk is defined and sym.stat.islnk == False
  38. - name: Enable dnsmasq configuration
  39. file:
  40. src: /etc/dnsmasq.d-available/01-kube-dns.conf
  41. dest: /etc/dnsmasq.d/01-kube-dns.conf
  42. state: link
  43. - name: Create dnsmasq manifests
  44. template:
  45. src: "{{item.file}}"
  46. dest: "{{kube_config_dir}}/{{item.file}}"
  47. with_items:
  48. - {file: dnsmasq-ds.yml, type: ds}
  49. - {file: dnsmasq-svc.yml, type: svc}
  50. register: manifests
  51. when: inventory_hostname == groups['kube-master'][0]
  52. #FIXME: remove manifests.changed condition if kubernetes/features#124 is implemented
  53. - name: Delete existing dnsmasq daemonset
  54. kube:
  55. name: dnsmasq
  56. namespace: "{{system_namespace}}"
  57. kubectl: "{{bin_dir}}/kubectl"
  58. resource: "ds"
  59. filename: "{{kube_config_dir}}/{{item.item.file}}"
  60. state: absent
  61. with_items: "{{ manifests.results }}"
  62. when: inventory_hostname == groups['kube-master'][0] and item.item.type == "ds" and (manifests.changed or dnsmasq_config.changed)
  63. - name: Start Resources
  64. kube:
  65. name: dnsmasq
  66. namespace: "{{system_namespace}}"
  67. kubectl: "{{bin_dir}}/kubectl"
  68. resource: "{{item.item.type}}"
  69. filename: "{{kube_config_dir}}/{{item.item.file}}"
  70. state: "{{item.changed | ternary('latest','present') }}"
  71. with_items: "{{ manifests.results }}"
  72. when: inventory_hostname == groups['kube-master'][0]
  73. - name: Check for dnsmasq port (pulling image and running container)
  74. wait_for:
  75. host: "{{dns_server}}"
  76. port: 53
  77. delay: 5
  78. when: inventory_hostname == groups['kube-node'][0]