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.

104 lines
3.1 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. - name: ensure dnsmasq.d-available directory exists
  7. file:
  8. path: /etc/dnsmasq.d-available
  9. state: directory
  10. - name: check system nameservers
  11. shell: awk '/^nameserver/ {print $NF}' /etc/resolv.conf
  12. changed_when: False
  13. register: system_nameservers
  14. - name: init system_and_upstream_dns_servers
  15. set_fact:
  16. system_and_upstream_dns_servers: "{{ upstream_dns_servers|default([]) }}"
  17. - name: combine upstream_dns_servers and system nameservers (only for docker_dns)
  18. set_fact:
  19. system_and_upstream_dns_servers: "{{ system_and_upstream_dns_servers | union(system_nameservers.stdout_lines) | unique }}"
  20. when: system_nameservers.stdout != "" and resolvconf_mode != 'host_resolvconf'
  21. - name: Write dnsmasq configuration
  22. template:
  23. src: 01-kube-dns.conf.j2
  24. dest: /etc/dnsmasq.d-available/01-kube-dns.conf
  25. mode: 0755
  26. backup: yes
  27. register: dnsmasq_config
  28. - name: Stat dnsmasq link
  29. stat:
  30. path: /etc/dnsmasq.d-available/01-kube-dns.conf
  31. register: dnsmasq_stat
  32. - name: Stat dnsmasq link
  33. stat:
  34. path: /etc/dnsmasq.d/01-kube-dns.conf
  35. register: sym
  36. - name: Move previous configuration
  37. command: mv /etc/dnsmasq.d/01-kube-dns.conf /etc/dnsmasq.d-available/01-kube-dns.conf.bak
  38. changed_when: False
  39. when: sym.stat.islnk is defined and sym.stat.islnk == False
  40. - name: Enable dnsmasq configuration
  41. file:
  42. src: /etc/dnsmasq.d-available/01-kube-dns.conf
  43. dest: /etc/dnsmasq.d/01-kube-dns.conf
  44. state: link
  45. - name: Create dnsmasq RBAC manifests
  46. template:
  47. src: "{{ item }}"
  48. dest: "{{ kube_config_dir }}/{{ item }}"
  49. with_items:
  50. - "dnsmasq-clusterrolebinding.yml"
  51. - "dnsmasq-serviceaccount.yml"
  52. when: rbac_enabled
  53. delegate_to: "{{ groups['kube-master'][0] }}"
  54. run_once: true
  55. - name: Apply dnsmasq RBAC manifests
  56. command: "{{ bin_dir }}/kubectl apply -f {{ kube_config_dir }}/{{ item }}"
  57. with_items:
  58. - "dnsmasq-clusterrolebinding.yml"
  59. - "dnsmasq-serviceaccount.yml"
  60. when: rbac_enabled
  61. delegate_to: "{{ groups['kube-master'][0] }}"
  62. run_once: true
  63. - name: Create dnsmasq manifests
  64. template:
  65. src: "{{item.file}}"
  66. dest: "{{kube_config_dir}}/{{item.file}}"
  67. with_items:
  68. - {name: dnsmasq, file: dnsmasq-deploy.yml, type: deployment}
  69. - {name: dnsmasq, file: dnsmasq-svc.yml, type: svc}
  70. - {name: dnsmasq-autoscaler, file: dnsmasq-autoscaler.yml.j2, type: deployment}
  71. register: manifests
  72. delegate_to: "{{ groups['kube-master'][0] }}"
  73. run_once: true
  74. - name: Start Resources
  75. kube:
  76. name: "{{item.item.name}}"
  77. namespace: "kube-system"
  78. kubectl: "{{bin_dir}}/kubectl"
  79. resource: "{{item.item.type}}"
  80. filename: "{{kube_config_dir}}/{{item.item.file}}"
  81. state: "latest"
  82. with_items: "{{ manifests.results }}"
  83. delegate_to: "{{ groups['kube-master'][0] }}"
  84. run_once: true
  85. - name: Check for dnsmasq port (pulling image and running container)
  86. wait_for:
  87. host: "{{dnsmasq_dns_server}}"
  88. port: 53
  89. timeout: 180
  90. when: inventory_hostname == groups['kube-node'][0] and groups['kube-node'][0] in ansible_play_hosts