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.

252 lines
6.7 KiB

  1. ---
  2. - include: pre-upgrade.yml
  3. tags: [upgrade, bootstrap-os]
  4. - name: Force binaries directory for Container Linux by CoreOS
  5. set_fact:
  6. bin_dir: "/opt/bin"
  7. when: ansible_os_family in ["CoreOS", "Container Linux by CoreOS"]
  8. tags: facts
  9. - name: check bin dir exists
  10. file:
  11. path: "{{bin_dir}}"
  12. state: directory
  13. owner: root
  14. become: true
  15. tags: bootstrap-os
  16. - include: gitinfos.yml
  17. when: run_gitinfos
  18. tags: facts
  19. - include: set_facts.yml
  20. tags: facts
  21. - name: gather os specific variables
  22. include_vars: "{{ item }}"
  23. with_first_found:
  24. - files:
  25. - "{{ ansible_distribution|lower }}-{{ ansible_distribution_version|lower|replace('/', '_') }}.yml"
  26. - "{{ ansible_distribution|lower }}-{{ ansible_distribution_release }}.yml"
  27. - "{{ ansible_distribution|lower }}-{{ ansible_distribution_major_version|lower|replace('/', '_') }}.yml"
  28. - "{{ ansible_distribution|lower }}.yml"
  29. - "{{ ansible_os_family|lower }}.yml"
  30. - defaults.yml
  31. paths:
  32. - ../vars
  33. skip: true
  34. tags: facts
  35. - name: Create kubernetes config directory
  36. file:
  37. path: "{{ kube_config_dir }}"
  38. state: directory
  39. owner: kube
  40. when: inventory_hostname in groups['k8s-cluster']
  41. tags: [kubelet, k8s-secrets, kube-controller-manager, kube-apiserver, bootstrap-os, apps, network, master, node]
  42. - name: Create kubernetes script directory
  43. file:
  44. path: "{{ kube_script_dir }}"
  45. state: directory
  46. owner: kube
  47. when: "inventory_hostname in groups['k8s-cluster']"
  48. tags: [k8s-secrets, bootstrap-os]
  49. - name: Create kubernetes manifests directory
  50. file:
  51. path: "{{ kube_manifest_dir }}"
  52. state: directory
  53. owner: kube
  54. when: "inventory_hostname in groups['k8s-cluster']"
  55. tags: [kubelet, bootstrap-os, master, node]
  56. - name: check cloud_provider value
  57. fail:
  58. msg: "If set the 'cloud_provider' var must be set either to 'generic', 'gce', 'aws', 'azure', 'openstack' or 'vsphere'"
  59. when:
  60. - cloud_provider is defined
  61. - cloud_provider not in ['generic', 'gce', 'aws', 'azure', 'openstack', 'vsphere']
  62. tags: [cloud-provider, facts]
  63. - include: "{{ cloud_provider }}-credential-check.yml"
  64. when:
  65. - cloud_provider is defined
  66. - cloud_provider in [ 'openstack', 'azure', 'vsphere' ]
  67. tags: [cloud-provider, facts]
  68. - name: Create cni directories
  69. file:
  70. path: "{{ item }}"
  71. state: directory
  72. owner: kube
  73. with_items:
  74. - "/etc/cni/net.d"
  75. - "/opt/cni/bin"
  76. when:
  77. - kube_network_plugin in ["calico", "weave", "canal"]
  78. - inventory_hostname in groups['k8s-cluster']
  79. tags: [network, calico, weave, canal, bootstrap-os]
  80. - name: Update package management cache (YUM)
  81. yum:
  82. update_cache: yes
  83. name: '*'
  84. register: yum_task_result
  85. until: yum_task_result|succeeded
  86. retries: 4
  87. delay: "{{ retry_stagger | random + 3 }}"
  88. when:
  89. - ansible_pkg_mgr == 'yum'
  90. - not is_atomic
  91. tags: bootstrap-os
  92. - name: Install latest version of python-apt for Debian distribs
  93. apt:
  94. name: python-apt
  95. state: latest
  96. update_cache: yes
  97. cache_valid_time: 3600
  98. when: ansible_os_family == "Debian"
  99. tags: bootstrap-os
  100. - name: Install python-dnf for latest RedHat versions
  101. command: dnf install -y python-dnf yum
  102. register: dnf_task_result
  103. until: dnf_task_result|succeeded
  104. retries: 4
  105. delay: "{{ retry_stagger | random + 3 }}"
  106. when:
  107. - ansible_distribution == "Fedora"
  108. - ansible_distribution_major_version > 21
  109. changed_when: False
  110. tags: bootstrap-os
  111. - name: Install epel-release on RedHat/CentOS
  112. shell: rpm -qa | grep epel-release || rpm -ivh {{ epel_rpm_download_url }}
  113. when:
  114. - ansible_distribution in ["CentOS","RedHat"]
  115. - not is_atomic
  116. register: epel_task_result
  117. until: epel_task_result|succeeded
  118. retries: 4
  119. delay: "{{ retry_stagger | random + 3 }}"
  120. changed_when: False
  121. check_mode: no
  122. tags: bootstrap-os
  123. - name: Install packages requirements
  124. action:
  125. module: "{{ ansible_pkg_mgr }}"
  126. name: "{{ item }}"
  127. state: latest
  128. register: pkgs_task_result
  129. until: pkgs_task_result|succeeded
  130. retries: 4
  131. delay: "{{ retry_stagger | random + 3 }}"
  132. with_items: "{{required_pkgs | default([]) | union(common_required_pkgs|default([]))}}"
  133. when: not (ansible_os_family in ["CoreOS", "Container Linux by CoreOS"] or is_atomic)
  134. tags: bootstrap-os
  135. # Todo : selinux configuration
  136. - name: Confirm selinux deployed
  137. stat:
  138. path: /etc/selinux/config
  139. when: ansible_os_family == "RedHat"
  140. register: slc
  141. - name: Set selinux policy to permissive
  142. selinux:
  143. policy: targeted
  144. state: permissive
  145. when:
  146. - ansible_os_family == "RedHat"
  147. - slc.stat.exists == True
  148. changed_when: False
  149. tags: bootstrap-os
  150. - name: Disable IPv6 DNS lookup
  151. lineinfile:
  152. dest: /etc/gai.conf
  153. line: "precedence ::ffff:0:0/96 100"
  154. state: present
  155. backup: yes
  156. when:
  157. - disable_ipv6_dns
  158. - not ansible_os_family in ["CoreOS", "Container Linux by CoreOS"]
  159. tags: bootstrap-os
  160. - name: set default sysctl file path
  161. set_fact:
  162. sysctl_file_path: "/etc/sysctl.d/99-sysctl.conf"
  163. tags: bootstrap-os
  164. - name: Stat sysctl file configuration
  165. stat:
  166. path: "{{sysctl_file_path}}"
  167. register: sysctl_file_stat
  168. tags: bootstrap-os
  169. - name: Change sysctl file path to link source if linked
  170. set_fact:
  171. sysctl_file_path: "{{sysctl_file_stat.stat.lnk_source}}"
  172. when:
  173. - sysctl_file_stat.stat.islnk is defined
  174. - sysctl_file_stat.stat.islnk
  175. tags: bootstrap-os
  176. - name: Enable ip forwarding
  177. sysctl:
  178. sysctl_file: "{{sysctl_file_path}}"
  179. name: net.ipv4.ip_forward
  180. value: 1
  181. state: present
  182. tags: bootstrap-os
  183. - name: Write cloud-config
  184. template:
  185. src: "{{ cloud_provider }}-cloud-config.j2"
  186. dest: "{{ kube_config_dir }}/cloud_config"
  187. group: "{{ kube_cert_group }}"
  188. mode: 0640
  189. when:
  190. - inventory_hostname in groups['k8s-cluster']
  191. - cloud_provider is defined
  192. - cloud_provider in [ 'openstack', 'azure', 'vsphere' ]
  193. tags: [cloud-provider]
  194. - include: etchosts.yml
  195. tags: [bootstrap-os, etchosts]
  196. - include: resolvconf.yml
  197. when:
  198. - dns_mode != 'none'
  199. - resolvconf_mode == 'host_resolvconf'
  200. tags: [bootstrap-os, resolvconf]
  201. - include: dhclient-hooks.yml
  202. when:
  203. - dns_mode != 'none'
  204. - resolvconf_mode == 'host_resolvconf'
  205. - not ansible_os_family in ["CoreOS", "Container Linux by CoreOS"]
  206. tags: [bootstrap-os, resolvconf]
  207. - include: dhclient-hooks-undo.yml
  208. when:
  209. - dns_mode != 'none'
  210. - resolvconf_mode != 'host_resolvconf'
  211. - not ansible_os_family in ["CoreOS", "Container Linux by CoreOS"]
  212. tags: [bootstrap-os, resolvconf]
  213. - name: Check if we are running inside a Azure VM
  214. stat:
  215. path: /var/lib/waagent/
  216. register: azure_check
  217. tags: bootstrap-os
  218. - include: growpart-azure-centos-7.yml
  219. when:
  220. - azure_check.stat.exists
  221. - ansible_distribution in ["CentOS","RedHat"]
  222. tags: bootstrap-os