2018-08-10 01:53:11 +08:00
|
|
|
---
|
2024-01-31 16:57:23 +08:00
|
|
|
- name: Cri-o | load vars
|
|
|
|
import_tasks: load_vars.yml
|
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Cri-o | check if fedora coreos
|
2020-03-17 18:12:21 +08:00
|
|
|
stat:
|
|
|
|
path: /run/ostree-booted
|
2021-02-10 21:36:59 +08:00
|
|
|
get_attributes: no
|
|
|
|
get_checksum: no
|
|
|
|
get_mime: no
|
2020-03-17 18:12:21 +08:00
|
|
|
register: ostree
|
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Cri-o | set is_ostree
|
2020-03-17 18:12:21 +08:00
|
|
|
set_fact:
|
|
|
|
is_ostree: "{{ ostree.stat.exists }}"
|
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Cri-o | get ostree version
|
2021-11-22 18:29:09 +08:00
|
|
|
shell: "set -o pipefail && rpm-ostree --version | awk -F\\' '/Version/{print $2}'"
|
|
|
|
args:
|
|
|
|
executable: /bin/bash
|
|
|
|
register: ostree_version
|
|
|
|
when: is_ostree
|
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Cri-o | Download cri-o
|
2022-10-19 20:47:05 +08:00
|
|
|
include_tasks: "../../../download/tasks/download_file.yml"
|
|
|
|
vars:
|
|
|
|
download: "{{ download_defaults | combine(downloads.crio) }}"
|
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Cri-o | special handling for amazon linux
|
2022-10-19 20:47:05 +08:00
|
|
|
import_tasks: "setup-amazon.yaml"
|
|
|
|
when: ansible_distribution in ["Amazon"]
|
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Cri-o | build a list of crio runtimes with Katacontainers runtimes
|
2020-10-23 18:07:46 +08:00
|
|
|
set_fact:
|
2023-07-05 11:36:54 +08:00
|
|
|
crio_runtimes: "{{ crio_runtimes + kata_runtimes }}"
|
2020-10-23 18:07:46 +08:00
|
|
|
when:
|
|
|
|
- kata_containers_enabled
|
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Cri-o | build a list of crio runtimes with crun runtime
|
2020-12-02 03:00:50 +08:00
|
|
|
set_fact:
|
|
|
|
crio_runtimes: "{{ crio_runtimes + [crun_runtime] }}"
|
|
|
|
when:
|
|
|
|
- crun_enabled
|
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Cri-o | build a list of crio runtimes with youki runtime
|
2022-01-22 06:01:07 +08:00
|
|
|
set_fact:
|
|
|
|
crio_runtimes: "{{ crio_runtimes + [youki_runtime] }}"
|
|
|
|
when:
|
|
|
|
- youki_enabled
|
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Cri-o | make sure needed folders exist in the system
|
2018-12-18 17:39:25 +08:00
|
|
|
with_items:
|
|
|
|
- /etc/crio
|
|
|
|
- /etc/containers
|
2020-04-21 19:12:55 +08:00
|
|
|
- /etc/systemd/system/crio.service.d
|
2018-12-18 17:39:25 +08:00
|
|
|
file:
|
|
|
|
path: "{{ item }}"
|
|
|
|
state: directory
|
2021-07-12 15:00:47 +08:00
|
|
|
mode: 0755
|
2018-12-18 17:39:25 +08:00
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Cri-o | install cri-o config
|
2020-11-04 00:54:03 +08:00
|
|
|
template:
|
|
|
|
src: crio.conf.j2
|
|
|
|
dest: /etc/crio/crio.conf
|
2021-07-12 15:00:47 +08:00
|
|
|
mode: 0644
|
2020-11-04 00:54:03 +08:00
|
|
|
register: config_install
|
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Cri-o | install config.json
|
2021-09-02 01:20:59 +08:00
|
|
|
template:
|
|
|
|
src: config.json.j2
|
|
|
|
dest: /etc/crio/config.json
|
2021-09-10 14:35:59 +08:00
|
|
|
mode: 0644
|
2021-09-02 01:20:59 +08:00
|
|
|
register: reg_auth_install
|
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Cri-o | copy binaries
|
2022-10-19 20:47:05 +08:00
|
|
|
copy:
|
|
|
|
src: "{{ local_release_dir }}/cri-o/bin/{{ item }}"
|
|
|
|
dest: "{{ bin_dir }}/{{ item }}"
|
|
|
|
mode: 0755
|
|
|
|
remote_src: true
|
2022-07-19 15:30:07 +08:00
|
|
|
with_items:
|
2022-10-19 20:47:05 +08:00
|
|
|
- "{{ crio_bin_files }}"
|
2023-07-26 22:36:22 +08:00
|
|
|
notify: Restart crio
|
2020-03-17 18:12:21 +08:00
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Cri-o | copy service file
|
2022-10-19 20:47:05 +08:00
|
|
|
copy:
|
|
|
|
src: "{{ local_release_dir }}/cri-o/contrib/crio.service"
|
|
|
|
dest: /etc/systemd/system/crio.service
|
|
|
|
mode: 0755
|
|
|
|
remote_src: true
|
2023-07-26 22:36:22 +08:00
|
|
|
notify: Restart crio
|
2020-03-17 18:12:21 +08:00
|
|
|
|
2024-04-01 13:21:33 +08:00
|
|
|
- name: Cri-o | configure crio to use kube reserved cgroups
|
|
|
|
ansible.builtin.copy:
|
|
|
|
dest: /etc/systemd/system/crio.service.d/00-slice.conf
|
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
mode: '0644'
|
|
|
|
content: |
|
|
|
|
[Service]
|
|
|
|
Slice={{ kube_reserved_cgroups_for_service_slice }}
|
|
|
|
notify: Restart crio
|
|
|
|
when:
|
|
|
|
- kube_reserved is defined and kube_reserved is true
|
|
|
|
- kube_reserved_cgroups_for_service_slice is defined
|
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Cri-o | update the bin dir for crio.service file
|
2023-05-19 06:46:33 +08:00
|
|
|
replace:
|
|
|
|
dest: /etc/systemd/system/crio.service
|
|
|
|
regexp: "/usr/local/bin/crio"
|
|
|
|
replace: "{{ bin_dir }}/crio"
|
2023-07-26 22:36:22 +08:00
|
|
|
notify: Restart crio
|
2023-05-19 06:46:33 +08:00
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Cri-o | copy default policy
|
2022-10-19 20:47:05 +08:00
|
|
|
copy:
|
|
|
|
src: "{{ local_release_dir }}/cri-o/contrib/policy.json"
|
|
|
|
dest: /etc/containers/policy.json
|
|
|
|
mode: 0755
|
|
|
|
remote_src: true
|
2023-07-26 22:36:22 +08:00
|
|
|
notify: Restart crio
|
2020-04-22 21:09:52 +08:00
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Cri-o | copy mounts.conf
|
2018-08-28 19:48:37 +08:00
|
|
|
copy:
|
|
|
|
src: mounts.conf
|
|
|
|
dest: /etc/containers/mounts.conf
|
2021-07-12 15:00:47 +08:00
|
|
|
mode: 0644
|
2018-08-28 19:48:37 +08:00
|
|
|
when:
|
|
|
|
- ansible_os_family == 'RedHat'
|
2023-07-26 22:36:22 +08:00
|
|
|
notify: Restart crio
|
2018-08-10 01:53:11 +08:00
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Cri-o | create directory for oci hooks
|
2018-08-10 01:53:11 +08:00
|
|
|
file:
|
|
|
|
path: /etc/containers/oci/hooks.d
|
|
|
|
state: directory
|
|
|
|
owner: root
|
|
|
|
mode: 0755
|
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Cri-o | set overlay driver
|
2023-06-26 18:15:45 +08:00
|
|
|
community.general.ini_file:
|
2022-10-19 20:47:05 +08:00
|
|
|
dest: /etc/containers/storage.conf
|
|
|
|
section: storage
|
|
|
|
option: "{{ item.option }}"
|
|
|
|
value: "{{ item.value }}"
|
|
|
|
mode: 0644
|
|
|
|
with_items:
|
|
|
|
- option: driver
|
|
|
|
value: '"overlay"'
|
|
|
|
- option: graphroot
|
|
|
|
value: '"/var/lib/containers/storage"'
|
2023-08-18 01:17:22 +08:00
|
|
|
- option: runroot
|
|
|
|
value: '"/var/run/containers/storage"'
|
2022-10-19 20:47:05 +08:00
|
|
|
|
2021-02-16 12:51:07 +08:00
|
|
|
# metacopy=on is available since 4.19 and was backported to RHEL 4.18 kernel
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Cri-o | set metacopy mount options correctly
|
2023-06-26 18:15:45 +08:00
|
|
|
community.general.ini_file:
|
2020-04-24 16:18:07 +08:00
|
|
|
dest: /etc/containers/storage.conf
|
|
|
|
section: storage.options.overlay
|
|
|
|
option: mountopt
|
2021-02-16 12:51:07 +08:00
|
|
|
value: '{{ ''"nodev"'' if ansible_kernel is version_compare(("4.18" if ansible_os_family == "RedHat" else "4.19"), "<") else ''"nodev,metacopy=on"'' }}'
|
2021-07-12 15:00:47 +08:00
|
|
|
mode: 0644
|
2020-04-24 16:18:07 +08:00
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Cri-o | create directory registries configs
|
2020-12-04 05:57:25 +08:00
|
|
|
file:
|
|
|
|
path: /etc/containers/registries.conf.d
|
|
|
|
state: directory
|
|
|
|
owner: root
|
|
|
|
mode: 0755
|
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Cri-o | write registries configs
|
2020-12-04 05:57:25 +08:00
|
|
|
template:
|
2022-01-05 23:36:40 +08:00
|
|
|
src: registry.conf.j2
|
|
|
|
dest: "/etc/containers/registries.conf.d/10-{{ item.prefix | default(item.location) | regex_replace(':', '_') }}.conf"
|
2021-07-12 15:00:47 +08:00
|
|
|
mode: 0644
|
2022-01-05 23:36:40 +08:00
|
|
|
loop: "{{ crio_registries }}"
|
2023-07-26 22:36:22 +08:00
|
|
|
notify: Restart crio
|
2022-01-05 23:36:40 +08:00
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Cri-o | configure unqualified registry settings
|
2022-01-05 23:36:40 +08:00
|
|
|
template:
|
|
|
|
src: unqualified.conf.j2
|
|
|
|
dest: "/etc/containers/registries.conf.d/01-unqualified.conf"
|
2022-01-11 16:45:16 +08:00
|
|
|
mode: 0644
|
2023-07-26 22:36:22 +08:00
|
|
|
notify: Restart crio
|
2020-12-04 05:57:25 +08:00
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Cri-o | write cri-o proxy drop-in
|
2020-04-21 19:12:55 +08:00
|
|
|
template:
|
|
|
|
src: http-proxy.conf.j2
|
|
|
|
dest: /etc/systemd/system/crio.service.d/http-proxy.conf
|
2021-07-12 15:00:47 +08:00
|
|
|
mode: 0644
|
2023-07-26 22:36:22 +08:00
|
|
|
notify: Restart crio
|
2020-04-24 16:18:07 +08:00
|
|
|
when: http_proxy is defined or https_proxy is defined
|
2020-10-07 15:10:42 +08:00
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Cri-o | configure the uid/gid space for user namespaces
|
2021-12-20 22:37:25 +08:00
|
|
|
lineinfile:
|
|
|
|
path: '{{ item.path }}'
|
|
|
|
line: '{{ item.entry }}'
|
|
|
|
regex: '^\s*{{ crio_remap_user }}:'
|
|
|
|
state: '{{ "present" if crio_remap_enable | bool else "absent" }}'
|
|
|
|
loop:
|
|
|
|
- path: /etc/subuid
|
|
|
|
entry: '{{ crio_remap_user }}:{{ crio_subuid_start }}:{{ crio_subuid_length }}'
|
|
|
|
- path: /etc/subgid
|
|
|
|
entry: '{{ crio_remap_user }}:{{ crio_subgid_start }}:{{ crio_subgid_length }}'
|
|
|
|
loop_control:
|
|
|
|
label: '{{ item.path }}'
|
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Cri-o | ensure crio service is started and enabled
|
2020-10-07 15:10:42 +08:00
|
|
|
service:
|
|
|
|
name: crio
|
|
|
|
daemon_reload: true
|
|
|
|
enabled: true
|
|
|
|
state: started
|
2020-11-04 00:54:03 +08:00
|
|
|
register: service_start
|
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Cri-o | trigger service restart only when needed
|
2023-06-30 17:51:57 +08:00
|
|
|
service:
|
2020-11-04 00:54:03 +08:00
|
|
|
name: crio
|
|
|
|
state: restarted
|
|
|
|
when:
|
2023-05-15 10:27:28 +08:00
|
|
|
- config_install.changed or reg_auth_install.changed
|
2020-11-04 00:54:03 +08:00
|
|
|
- not service_start.changed
|
2020-10-07 15:10:42 +08:00
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Cri-o | verify that crio is running
|
2024-01-31 16:57:23 +08:00
|
|
|
command: "{{ bin_dir }}/{{ crio_status_command }} info"
|
2020-10-07 15:10:42 +08:00
|
|
|
register: get_crio_info
|
|
|
|
until: get_crio_info is succeeded
|
|
|
|
changed_when: false
|
|
|
|
retries: 5
|
|
|
|
delay: "{{ retry_stagger | random + 3 }}"
|