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.

95 lines
2.5 KiB

9 years ago
9 years ago
8 years ago
9 years ago
8 years ago
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: Write dnsmasq configuration
  11. template:
  12. src: 01-kube-dns.conf.j2
  13. dest: /etc/dnsmasq.d-available/01-kube-dns.conf
  14. mode: 0755
  15. backup: yes
  16. - name: Stat dnsmasq configuration
  17. stat: path=/etc/dnsmasq.d/01-kube-dns.conf
  18. register: sym
  19. - name: Move previous configuration
  20. command: mv /etc/dnsmasq.d/01-kube-dns.conf /etc/dnsmasq.d-available/01-kube-dns.conf.bak
  21. changed_when: False
  22. when: sym.stat.islnk is defined and sym.stat.islnk == False
  23. - name: Enable dnsmasq configuration
  24. file:
  25. src: /etc/dnsmasq.d-available/01-kube-dns.conf
  26. dest: /etc/dnsmasq.d/01-kube-dns.conf
  27. state: link
  28. - name: Create dnsmasq pod manifest
  29. template: src=dnsmasq-pod.yml dest=/etc/kubernetes/manifests/dnsmasq-pod.manifest
  30. - name: Check for dnsmasq port (pulling image and running container)
  31. wait_for:
  32. port: 53
  33. delay: 5
  34. - name: check resolvconf
  35. stat: path=/etc/resolvconf/resolv.conf.d/head
  36. register: resolvconf
  37. - name: target resolv.conf file
  38. set_fact:
  39. resolvconffile: >-
  40. {%- if resolvconf.stat.exists == True -%}/etc/resolvconf/resolv.conf.d/head{%- else -%}/etc/resolv.conf{%- endif -%}
  41. - name: Add search resolv.conf
  42. lineinfile:
  43. line: "search {{ [ 'default.svc.' + dns_domain, 'svc.' + dns_domain, dns_domain ] | join(' ') }}"
  44. dest: "{{resolvconffile}}"
  45. state: present
  46. insertbefore: BOF
  47. backup: yes
  48. follow: yes
  49. - name: Add local dnsmasq to resolv.conf
  50. lineinfile:
  51. line: "nameserver 127.0.0.1"
  52. dest: "{{resolvconffile}}"
  53. state: present
  54. insertafter: "^search.*$"
  55. backup: yes
  56. follow: yes
  57. - name: Add options to resolv.conf
  58. lineinfile:
  59. line: options {{ item }}
  60. dest: "{{resolvconffile}}"
  61. state: present
  62. regexp: "^options.*{{ item }}$"
  63. insertafter: EOF
  64. backup: yes
  65. follow: yes
  66. with_items:
  67. - timeout:2
  68. - attempts:2
  69. - name: disable resolv.conf modification by dhclient
  70. copy: src=dhclient_nodnsupdate dest=/etc/dhcp/dhclient-enter-hooks.d/nodnsupdate mode=0755 backup=yes
  71. when: ansible_os_family == "Debian"
  72. - name: disable resolv.conf modification by dhclient
  73. copy: src=dhclient_nodnsupdate dest=/etc/dhcp/dhclient.d/nodnsupdate mode=u+x backup=yes
  74. when: ansible_os_family == "RedHat"
  75. - name: update resolvconf
  76. command: resolvconf -u
  77. changed_when: False
  78. when: resolvconf.stat.exists == True
  79. - meta: flush_handlers