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.

287 lines
6.7 KiB

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