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.

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