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.

102 lines
3.0 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 }}.j2"
  48. dest: "{{ kube_config_dir }}/{{ item }}"
  49. with_items:
  50. - "dnsmasq-clusterrolebinding.yml"
  51. - "dnsmasq-serviceaccount.yml"
  52. delegate_to: "{{ groups['kube-master'][0] }}"
  53. run_once: true
  54. - name: Apply dnsmasq RBAC manifests
  55. command: "{{ bin_dir }}/kubectl apply -f {{ kube_config_dir }}/{{ item }}"
  56. with_items:
  57. - "dnsmasq-clusterrolebinding.yml"
  58. - "dnsmasq-serviceaccount.yml"
  59. delegate_to: "{{ groups['kube-master'][0] }}"
  60. run_once: true
  61. - name: Create dnsmasq manifests
  62. template:
  63. src: "{{item.file}}.j2"
  64. dest: "{{kube_config_dir}}/{{item.file}}"
  65. with_items:
  66. - {name: dnsmasq, file: dnsmasq-deploy.yml, type: deployment}
  67. - {name: dnsmasq, file: dnsmasq-svc.yml, type: svc}
  68. - {name: dnsmasq-autoscaler, file: dnsmasq-autoscaler.yml, type: deployment}
  69. register: manifests
  70. delegate_to: "{{ groups['kube-master'][0] }}"
  71. run_once: true
  72. - name: Start Resources
  73. kube:
  74. name: "{{item.item.name}}"
  75. namespace: "kube-system"
  76. kubectl: "{{bin_dir}}/kubectl"
  77. resource: "{{item.item.type}}"
  78. filename: "{{kube_config_dir}}/{{item.item.file}}"
  79. state: "latest"
  80. with_items: "{{ manifests.results }}"
  81. delegate_to: "{{ groups['kube-master'][0] }}"
  82. run_once: true
  83. - name: Check for dnsmasq port (pulling image and running container)
  84. wait_for:
  85. host: "{{dnsmasq_dns_server}}"
  86. port: 53
  87. timeout: 180
  88. when: inventory_hostname == groups['kube-node'][0] and groups['kube-node'][0] in ansible_play_hosts