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.

176 lines
5.7 KiB

6 years ago
6 years ago
6 years ago
6 years ago
  1. ---
  2. - name: Force binaries directory for Flatcar Container Linux by Kinvolk
  3. set_fact:
  4. bin_dir: "/opt/bin"
  5. when: ansible_os_family in ["Flatcar Container Linux by Kinvolk"]
  6. tags:
  7. - facts
  8. - name: check if booted with ostree
  9. stat:
  10. path: /run/ostree-booted
  11. register: ostree
  12. - name: set is_fedora_coreos
  13. lineinfile:
  14. path: /etc/os-release
  15. line: "VARIANT_ID=coreos"
  16. state: present
  17. check_mode: yes
  18. register: os_variant_coreos
  19. changed_when: false
  20. - name: set is_fedora_coreos
  21. set_fact:
  22. is_fedora_coreos: "{{ ostree.stat.exists and os_variant_coreos is not changed }}"
  23. - name: check resolvconf
  24. command: which resolvconf
  25. register: resolvconf
  26. failed_when: false
  27. changed_when: false
  28. check_mode: no
  29. - name: check systemd-resolved
  30. # noqa 303 Should we use service_facts for this?
  31. command: systemctl is-active systemd-resolved
  32. register: systemd_resolved_enabled
  33. failed_when: false
  34. changed_when: false
  35. check_mode: no
  36. - name: set dns facts
  37. set_fact:
  38. resolvconf: >-
  39. {%- if resolvconf.rc == 0 -%}true{%- else -%}false{%- endif -%}
  40. bogus_domains: |-
  41. {% for d in [ 'default.svc.' + dns_domain, 'svc.' + dns_domain ] + searchdomains|default([]) -%}
  42. {{ dns_domain }}.{{ d }}./{{ d }}.{{ d }}./com.{{ d }}./
  43. {%- endfor %}
  44. cloud_resolver: >-
  45. {%- if cloud_provider is defined and cloud_provider == 'gce' -%}
  46. ['169.254.169.254']
  47. {%- elif cloud_provider is defined and cloud_provider == 'aws' -%}
  48. ['169.254.169.253']
  49. {%- else -%}
  50. []
  51. {%- endif -%}
  52. - name: check if kubelet is configured
  53. stat:
  54. path: "{{ kube_config_dir }}/kubelet.env"
  55. register: kubelet_configured
  56. changed_when: false
  57. - name: check if early DNS configuration stage
  58. set_fact:
  59. dns_early: >-
  60. {%- if kubelet_configured.stat.exists -%}false{%- else -%}true{%- endif -%}
  61. - name: target resolv.conf files
  62. set_fact:
  63. resolvconffile: /etc/resolv.conf
  64. base: >-
  65. {%- if resolvconf|bool -%}/etc/resolvconf/resolv.conf.d/base{%- endif -%}
  66. head: >-
  67. {%- if resolvconf|bool -%}/etc/resolvconf/resolv.conf.d/head{%- endif -%}
  68. when: not ansible_os_family in ["Flatcar Container Linux by Kinvolk"] and not is_fedora_coreos
  69. - name: target temporary resolvconf cloud init file (Flatcar Container Linux by Kinvolk / Fedora CoreOS)
  70. set_fact:
  71. resolvconffile: /tmp/resolveconf_cloud_init_conf
  72. when: ansible_os_family in ["Flatcar Container Linux by Kinvolk"] or is_fedora_coreos
  73. - name: check if /etc/dhclient.conf exists
  74. stat:
  75. path: /etc/dhclient.conf
  76. register: dhclient_stat
  77. - name: target dhclient conf file for /etc/dhclient.conf
  78. set_fact:
  79. dhclientconffile: /etc/dhclient.conf
  80. when: dhclient_stat.stat.exists
  81. - name: check if /etc/dhcp/dhclient.conf exists
  82. stat:
  83. path: /etc/dhcp/dhclient.conf
  84. register: dhcp_dhclient_stat
  85. - name: target dhclient conf file for /etc/dhcp/dhclient.conf
  86. set_fact:
  87. dhclientconffile: /etc/dhcp/dhclient.conf
  88. when: dhcp_dhclient_stat.stat.exists
  89. - name: target dhclient hook file for Red Hat family
  90. set_fact:
  91. dhclienthookfile: /etc/dhcp/dhclient.d/zdnsupdate.sh
  92. when: ansible_os_family == "RedHat"
  93. - name: target dhclient hook file for Debian family
  94. set_fact:
  95. dhclienthookfile: /etc/dhcp/dhclient-exit-hooks.d/zdnsupdate
  96. when: ansible_os_family == "Debian"
  97. - name: generate search domains to resolvconf
  98. set_fact:
  99. searchentries:
  100. search {{ ([ 'default.svc.' + dns_domain, 'svc.' + dns_domain ] + searchdomains|default([])) | join(' ') }}
  101. domainentry:
  102. domain {{ dns_domain }}
  103. supersede_search:
  104. supersede domain-search "{{ ([ 'default.svc.' + dns_domain, 'svc.' + dns_domain ] + searchdomains|default([])) | join('", "') }}";
  105. supersede_domain:
  106. supersede domain-name "{{ dns_domain }}";
  107. - name: pick coredns cluster IP or default resolver
  108. set_fact:
  109. coredns_server: |-
  110. {%- if dns_mode == 'coredns' and not dns_early|bool -%}
  111. {{ [ skydns_server ] }}
  112. {%- elif dns_mode == 'coredns_dual' and not dns_early|bool -%}
  113. {{ [ skydns_server ] + [ skydns_server_secondary ] }}
  114. {%- elif dns_mode == 'manual' and not dns_early|bool -%}
  115. {{ ( manual_dns_server.split(',') | list) }}
  116. {%- elif dns_early|bool -%}
  117. {{ upstream_dns_servers|default([]) }}
  118. {%- endif -%}
  119. - name: generate nameservers to resolvconf
  120. set_fact:
  121. nameserverentries:
  122. nameserver {{ ( coredns_server + nameservers|d([]) + cloud_resolver|d([])) | unique | join(',nameserver ') }}
  123. supersede_nameserver:
  124. supersede domain-name-servers {{ ( coredns_server + nameservers|d([]) + cloud_resolver|d([])) | unique | join(', ') }};
  125. - name: gather os specific variables
  126. include_vars: "{{ item }}"
  127. with_first_found:
  128. - files:
  129. - "{{ ansible_distribution|lower }}-{{ ansible_distribution_version|lower|replace('/', '_') }}.yml"
  130. - "{{ ansible_distribution|lower }}-{{ ansible_distribution_release }}.yml"
  131. - "{{ ansible_distribution|lower }}-{{ ansible_distribution_major_version|lower|replace('/', '_') }}.yml"
  132. - "{{ ansible_distribution|lower }}.yml"
  133. - "{{ ansible_os_family|lower }}.yml"
  134. - defaults.yml
  135. paths:
  136. - ../vars
  137. skip: true
  138. - name: set etcd vars if using kubeadm mode
  139. set_fact:
  140. etcd_cert_dir: "{{ kube_cert_dir }}"
  141. kube_etcd_cacert_file: "etcd/ca.crt"
  142. kube_etcd_cert_file: "apiserver-etcd-client.crt"
  143. kube_etcd_key_file: "apiserver-etcd-client.key"
  144. when:
  145. - etcd_kubeadm_enabled
  146. - name: check /usr readonly
  147. stat:
  148. path: "/usr"
  149. register: usr
  150. - name: set alternate flexvolume path
  151. set_fact:
  152. kubelet_flexvolumes_plugins_dir: /var/lib/kubelet/volumeplugins
  153. when: not usr.stat.writeable