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.

210 lines
5.6 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. ---
  2. - name: check if fedora coreos
  3. stat:
  4. path: /run/ostree-booted
  5. get_attributes: no
  6. get_checksum: no
  7. get_mime: no
  8. register: ostree
  9. - name: set is_ostree
  10. set_fact:
  11. is_ostree: "{{ ostree.stat.exists }}"
  12. - name: gather os specific variables
  13. include_vars: "{{ item }}"
  14. with_first_found:
  15. - files:
  16. - "{{ ansible_distribution|lower }}-{{ ansible_distribution_version|lower|replace('/', '_') }}.yml"
  17. - "{{ ansible_distribution|lower }}-{{ ansible_distribution_release }}.yml"
  18. - "{{ ansible_distribution|lower }}-{{ ansible_distribution_major_version|lower|replace('/', '_') }}.yml"
  19. - "{{ ansible_distribution|lower }}.yml"
  20. - "{{ ansible_os_family|lower }}-{{ ansible_architecture }}.yml"
  21. - "{{ ansible_os_family|lower }}.yml"
  22. - defaults.yml
  23. paths:
  24. - ../vars
  25. skip: true
  26. tags:
  27. - facts
  28. - name: disable unified_cgroup_hierarchy in Fedora 31+
  29. command: grubby --update-kernel=ALL --args="systemd.unified_cgroup_hierarchy=0"
  30. when:
  31. - ansible_distribution == "Fedora"
  32. - (ansible_distribution_major_version | int) >= 31
  33. - ansible_proc_cmdline['systemd.unified_cgroup_hierarchy'] is not defined or ansible_proc_cmdline['systemd.unified_cgroup_hierarchy'] != '0'
  34. - not is_ostree
  35. - name: reboot in Fedora 31+
  36. reboot:
  37. when:
  38. - ansible_distribution == "Fedora"
  39. - (ansible_distribution_major_version | int) >= 31
  40. - ansible_proc_cmdline['systemd.unified_cgroup_hierarchy'] is not defined or ansible_proc_cmdline['systemd.unified_cgroup_hierarchy'] != '0'
  41. - not is_ostree
  42. - name: import crio repo
  43. import_tasks: "crio_repo.yml"
  44. when: crio_add_repos
  45. - include_role: # noqa unnamed-task
  46. name: container-engine/crictl
  47. - name: Build a list of crio runtimes with Katacontainers runtimes
  48. set_fact:
  49. crio_runtimes: "{{ crio_runtimes + kata_runtimes }}"
  50. when:
  51. - kata_containers_enabled
  52. - name: Build a list of crio runtimes with crun runtime
  53. set_fact:
  54. crio_runtimes: "{{ crio_runtimes + [crun_runtime] }}"
  55. when:
  56. - crun_enabled
  57. - name: Make sure needed folders exist in the system
  58. with_items:
  59. - /etc/crio
  60. - /etc/containers
  61. - /etc/systemd/system/crio.service.d
  62. file:
  63. path: "{{ item }}"
  64. state: directory
  65. mode: 0755
  66. - name: Install cri-o config
  67. template:
  68. src: crio.conf.j2
  69. dest: /etc/crio/crio.conf
  70. mode: 0644
  71. register: config_install
  72. - name: Add skopeo pkg to install
  73. set_fact:
  74. crio_packages: "{{ crio_packages + skopeo_packages }}"
  75. when:
  76. - not skip_downloads|default(false)
  77. - download_run_once
  78. - name: Add libseccomp2 package from Debian Backports to install
  79. set_fact:
  80. crio_packages: "{{ crio_debian_buster_backports_packages + crio_packages }}"
  81. when:
  82. - ansible_distribution == "Debian"
  83. - ansible_distribution_version == "10"
  84. - name: Install cri-o packages
  85. package:
  86. name: "{{ item }}"
  87. state: present
  88. when: not is_ostree
  89. with_items: "{{ crio_packages }}"
  90. register: package_install
  91. until: package_install is succeeded
  92. retries: 4
  93. delay: "{{ retry_stagger | d(3) }}"
  94. - name: Check if already installed
  95. stat:
  96. path: "/bin/crio"
  97. get_attributes: no
  98. get_checksum: no
  99. get_mime: no
  100. register: need_bootstrap_crio
  101. when: is_ostree
  102. - name: Install cri-o packages with osttree
  103. command: "rpm-ostree install {{ crio_packages|join(' ') }}"
  104. when:
  105. - is_ostree
  106. - not need_bootstrap_crio.stat.exists
  107. become: true
  108. - name: Reboot immediately for updated ostree
  109. reboot:
  110. become: true
  111. when:
  112. - is_ostree
  113. - not need_bootstrap_crio.stat.exists
  114. - name: Remove example CNI configs
  115. file:
  116. path: "/etc/cni/net.d/{{ item }}"
  117. state: absent
  118. loop:
  119. - 100-crio-bridge.conf
  120. - 200-loopback.conf
  121. - name: Copy mounts.conf
  122. copy:
  123. src: mounts.conf
  124. dest: /etc/containers/mounts.conf
  125. mode: 0644
  126. when:
  127. - ansible_os_family == 'RedHat'
  128. notify: restart crio
  129. - name: Create directory for oci hooks
  130. file:
  131. path: /etc/containers/oci/hooks.d
  132. state: directory
  133. owner: root
  134. mode: 0755
  135. # metacopy=on is available since 4.19 and was backported to RHEL 4.18 kernel
  136. - name: Set metacopy mount options correctly
  137. ini_file:
  138. dest: /etc/containers/storage.conf
  139. section: storage.options.overlay
  140. option: mountopt
  141. value: '{{ ''"nodev"'' if ansible_kernel is version_compare(("4.18" if ansible_os_family == "RedHat" else "4.19"), "<") else ''"nodev,metacopy=on"'' }}'
  142. mode: 0644
  143. - name: Create directory registries configs
  144. file:
  145. path: /etc/containers/registries.conf.d
  146. state: directory
  147. owner: root
  148. mode: 0755
  149. - name: Write registries mirror configs
  150. template:
  151. src: registry-mirror.conf.j2
  152. dest: "/etc/containers/registries.conf.d/{{ item.prefix }}.conf"
  153. mode: 0644
  154. loop: "{{ crio_registries_mirrors }}"
  155. notify: restart crio
  156. - name: Write cri-o proxy drop-in
  157. template:
  158. src: http-proxy.conf.j2
  159. dest: /etc/systemd/system/crio.service.d/http-proxy.conf
  160. mode: 0644
  161. notify: restart crio
  162. when: http_proxy is defined or https_proxy is defined
  163. - name: Ensure crio service is started and enabled
  164. service:
  165. name: crio
  166. daemon_reload: true
  167. enabled: true
  168. state: started
  169. register: service_start
  170. - name: Trigger service restart only when needed
  171. service: # noqa 503
  172. name: crio
  173. state: restarted
  174. when:
  175. - config_install.changed
  176. - not package_install.changed
  177. - not service_start.changed
  178. - name: Verify that crio is running
  179. command: "crio-status info"
  180. register: get_crio_info
  181. until: get_crio_info is succeeded
  182. changed_when: false
  183. retries: 5
  184. delay: "{{ retry_stagger | random + 3 }}"