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.

224 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: cloud_provider is defined and cloud_provider not in ['generic', 'gce', 'aws', 'azure', 'openstack', 'vsphere']
  60. tags: [cloud-provider, facts]
  61. - include: "{{ cloud_provider }}-credential-check.yml"
  62. when: cloud_provider is defined and cloud_provider in [ 'openstack', 'azure', 'vsphere' ]
  63. tags: [cloud-provider, facts]
  64. - name: Create cni directories
  65. file:
  66. path: "{{ item }}"
  67. state: directory
  68. owner: kube
  69. with_items:
  70. - "/etc/cni/net.d"
  71. - "/opt/cni/bin"
  72. when: kube_network_plugin in ["calico", "weave", "canal"] and "{{ inventory_hostname in groups['k8s-cluster'] }}"
  73. tags: [network, calico, weave, canal, bootstrap-os]
  74. - name: Update package management cache (YUM)
  75. yum:
  76. update_cache: yes
  77. name: '*'
  78. register: yum_task_result
  79. until: yum_task_result|succeeded
  80. retries: 4
  81. delay: "{{ retry_stagger | random + 3 }}"
  82. when: ansible_pkg_mgr == 'yum' and not is_atomic
  83. tags: bootstrap-os
  84. - name: Install latest version of python-apt for Debian distribs
  85. apt:
  86. name: python-apt
  87. state: latest
  88. update_cache: yes
  89. cache_valid_time: 3600
  90. when: ansible_os_family == "Debian"
  91. tags: bootstrap-os
  92. - name: Install python-dnf for latest RedHat versions
  93. command: dnf install -y python-dnf yum
  94. register: dnf_task_result
  95. until: dnf_task_result|succeeded
  96. retries: 4
  97. delay: "{{ retry_stagger | random + 3 }}"
  98. when: ansible_distribution == "Fedora" and
  99. ansible_distribution_major_version > 21
  100. changed_when: False
  101. tags: bootstrap-os
  102. - name: Install epel-release on RedHat/CentOS
  103. shell: rpm -qa | grep epel-release || rpm -ivh {{ epel_rpm_download_url }}
  104. when: ansible_distribution in ["CentOS","RedHat"] and not is_atomic
  105. register: epel_task_result
  106. until: epel_task_result|succeeded
  107. retries: 4
  108. delay: "{{ retry_stagger | random + 3 }}"
  109. changed_when: False
  110. check_mode: no
  111. tags: bootstrap-os
  112. - name: Install packages requirements
  113. action:
  114. module: "{{ ansible_pkg_mgr }}"
  115. name: "{{ item }}"
  116. state: latest
  117. register: pkgs_task_result
  118. until: pkgs_task_result|succeeded
  119. retries: 4
  120. delay: "{{ retry_stagger | random + 3 }}"
  121. with_items: "{{required_pkgs | default([]) | union(common_required_pkgs|default([]))}}"
  122. when: not (ansible_os_family in ["CoreOS", "Container Linux by CoreOS"] or is_atomic)
  123. tags: bootstrap-os
  124. # Todo : selinux configuration
  125. - name: Confirm selinux deployed
  126. stat:
  127. path: /etc/selinux/config
  128. when: ansible_os_family == "RedHat"
  129. register: slc
  130. - name: Set selinux policy to permissive
  131. selinux:
  132. policy: targeted
  133. state: permissive
  134. when: ansible_os_family == "RedHat" and slc.stat.exists == True
  135. changed_when: False
  136. tags: bootstrap-os
  137. - name: Disable IPv6 DNS lookup
  138. lineinfile:
  139. dest: /etc/gai.conf
  140. line: "precedence ::ffff:0:0/96 100"
  141. state: present
  142. backup: yes
  143. when: disable_ipv6_dns and not ansible_os_family in ["CoreOS", "Container Linux by CoreOS"]
  144. tags: bootstrap-os
  145. - name: set default sysctl file path
  146. set_fact:
  147. sysctl_file_path: "/etc/sysctl.d/99-sysctl.conf"
  148. tags: bootstrap-os
  149. - name: Stat sysctl file configuration
  150. stat:
  151. path: "{{sysctl_file_path}}"
  152. register: sysctl_file_stat
  153. tags: bootstrap-os
  154. - name: Change sysctl file path to link source if linked
  155. set_fact:
  156. sysctl_file_path: "{{sysctl_file_stat.stat.lnk_source}}"
  157. when: sysctl_file_stat.stat.islnk is defined and sysctl_file_stat.stat.islnk
  158. tags: bootstrap-os
  159. - name: Enable ip forwarding
  160. sysctl:
  161. sysctl_file: "{{sysctl_file_path}}"
  162. name: net.ipv4.ip_forward
  163. value: 1
  164. state: present
  165. tags: bootstrap-os
  166. - name: Write cloud-config
  167. template:
  168. src: "{{ cloud_provider }}-cloud-config.j2"
  169. dest: "{{ kube_config_dir }}/cloud_config"
  170. group: "{{ kube_cert_group }}"
  171. mode: 0640
  172. when: inventory_hostname in groups['k8s-cluster'] and cloud_provider is defined and cloud_provider in [ 'openstack', 'azure', 'vsphere' ]
  173. tags: [cloud-provider]
  174. - include: etchosts.yml
  175. tags: [bootstrap-os, etchosts]
  176. - include: resolvconf.yml
  177. when: dns_mode != 'none' and resolvconf_mode == 'host_resolvconf'
  178. tags: [bootstrap-os, resolvconf]
  179. - include: dhclient-hooks.yml
  180. when: dns_mode != 'none' and resolvconf_mode == 'host_resolvconf' and not ansible_os_family in ["CoreOS", "Container Linux by CoreOS"]
  181. tags: [bootstrap-os, resolvconf]
  182. - include: dhclient-hooks-undo.yml
  183. when: dns_mode != 'none' and resolvconf_mode != 'host_resolvconf' and not ansible_os_family in ["CoreOS", "Container Linux by CoreOS"]
  184. tags: [bootstrap-os, resolvconf]
  185. - name: Check if we are running inside a Azure VM
  186. stat:
  187. path: /var/lib/waagent/
  188. register: azure_check
  189. tags: bootstrap-os
  190. - include: growpart-azure-centos-7.yml
  191. when: azure_check.stat.exists and
  192. ansible_distribution in ["CentOS","RedHat"]
  193. tags: bootstrap-os