2019-06-29 21:09:20 +00:00
---
2020-03-17 21:31:27 +00:00
- name : check if fedora coreos
stat :
path : /run/ostree-booted
2021-02-10 13:36:59 +00:00
get_attributes : no
get_checksum : no
get_mime : no
2020-03-17 21:31:27 +00:00
register : ostree
- name : set is_ostree
set_fact :
is_ostree : "{{ ostree.stat.exists }}"
2019-06-29 21:09:20 +00:00
- name : Fail containerd setup if distribution is not supported
fail :
msg : "{{ ansible_distribution }} is not supported by containerd."
when :
2021-10-01 16:11:23 +00:00
- not ansible_distribution in ["CentOS", "OracleLinux", "RedHat", "Ubuntu", "Debian", "Fedora", "AlmaLinux", "Amazon", "Flatcar", "Flatcar Container Linux by Kinvolk"]
2019-06-29 21:09:20 +00:00
2019-07-11 06:46:54 +00:00
- name : gather os specific variables
include_vars : "{{ item }}"
with_first_found :
- files :
- "{{ ansible_distribution|lower }}-{{ ansible_distribution_version|lower|replace('/', '_') }}.yml"
- "{{ ansible_distribution|lower }}-{{ ansible_distribution_release|lower }}-{{ host_architecture }}.yml"
- "{{ ansible_distribution|lower }}-{{ ansible_distribution_release|lower }}.yml"
- "{{ ansible_distribution|lower }}-{{ ansible_distribution_major_version|lower|replace('/', '_') }}.yml"
- "{{ ansible_distribution|lower }}-{{ host_architecture }}.yml"
- "{{ ansible_distribution|lower }}.yml"
- "{{ ansible_os_family|lower }}-{{ host_architecture }}.yml"
- "{{ ansible_os_family|lower }}.yml"
- defaults.yml
paths :
- ../vars
skip : true
tags :
- facts
2019-06-29 21:09:20 +00:00
2020-07-28 08:39:08 +00:00
- name : disable unified_cgroup_hierarchy in Fedora 31+
command : grubby --update-kernel=ALL --args="systemd.unified_cgroup_hierarchy=0"
2020-05-08 14:55:43 +00:00
when :
- ansible_distribution == "Fedora"
- (ansible_distribution_major_version | int) >= 31
- ansible_proc_cmdline['systemd.unified_cgroup_hierarchy'] is not defined or ansible_proc_cmdline['systemd.unified_cgroup_hierarchy'] != '0'
2021-07-15 07:00:48 +00:00
- not is_ostree
2020-05-08 14:55:43 +00:00
- name : reboot in Fedora 31+
reboot :
when :
- ansible_distribution == "Fedora"
- (ansible_distribution_major_version | int) >= 31
- ansible_proc_cmdline['systemd.unified_cgroup_hierarchy'] is not defined or ansible_proc_cmdline['systemd.unified_cgroup_hierarchy'] != '0'
2021-07-15 07:00:48 +00:00
- not is_ostree
2020-05-08 14:55:43 +00:00
2019-07-11 06:46:54 +00:00
- include_tasks : containerd_repo.yml
2021-10-01 16:11:23 +00:00
when : not (is_ostree or (ansible_distribution == "Flatcar Container Linux by Kinvolk") or (ansible_distribution == "Flatcar"))
2019-07-11 06:46:54 +00:00
2020-01-29 09:24:14 +00:00
- name : Create containerd service systemd directory if it doesn't exist
file :
path : /etc/systemd/system/containerd.service.d
state : directory
2021-07-12 07:00:47 +00:00
mode : 0755
2020-01-29 09:24:14 +00:00
- name : Write containerd proxy drop-in
template :
src : http-proxy.conf.j2
dest : /etc/systemd/system/containerd.service.d/http-proxy.conf
2021-07-12 07:00:47 +00:00
mode : 0644
2020-01-29 09:24:14 +00:00
notify : restart containerd
when : http_proxy is defined or https_proxy is defined
2019-07-11 06:46:54 +00:00
- name : ensure containerd config directory
file :
dest : "{{ containerd_cfg_dir }}"
state : directory
mode : 0755
owner : root
group : root
- name : Copy containerd config file
2019-06-29 21:09:20 +00:00
template :
src : config.toml.j2
2019-07-11 06:46:54 +00:00
dest : "{{ containerd_cfg_dir }}/config.toml"
owner : "root"
2021-04-12 08:02:00 +00:00
mode : 0640
2019-07-11 06:46:54 +00:00
notify : restart containerd
2019-06-29 21:09:20 +00:00
2019-07-11 06:46:54 +00:00
# This is required to ensure any apt upgrade will not break kubernetes
- name : Set containerd pin priority to apt_preferences on Debian family
2021-01-08 22:29:43 +00:00
copy :
content : |
Package : {{ containerd_package }}
Pin : version {{ containerd_version }}*
Pin-Priority : 1001
2019-07-11 06:46:54 +00:00
dest : "/etc/apt/preferences.d/containerd"
owner : "root"
mode : 0644
2021-01-08 22:29:43 +00:00
when : ansible_pkg_mgr == 'apt'
2019-07-11 06:46:54 +00:00
- name : ensure containerd packages are installed
2021-01-07 16:36:03 +00:00
package :
name : "{{ containerd_package_info.pkgs }}"
2019-07-11 06:46:54 +00:00
state : present
2021-01-07 16:36:03 +00:00
module_defaults :
apt :
update_cache : true
dnf :
enablerepo : "{{ containerd_package_info.enablerepo | default(omit) }}"
yum :
enablerepo : "{{ containerd_package_info.enablerepo | default(omit) }}"
zypper :
update_cache : true
2019-07-11 06:46:54 +00:00
register : containerd_task_result
until : containerd_task_result is succeeded
retries : 4
delay : "{{ retry_stagger | d(3) }}"
notify : restart containerd
when :
2021-10-01 16:11:23 +00:00
- not (is_ostree or (ansible_distribution == "Flatcar Container Linux by Kinvolk") or (ansible_distribution == "Flatcar"))
2019-07-11 06:46:54 +00:00
- containerd_package_info.pkgs|length > 0
2021-07-12 07:00:47 +00:00
- include_role : # noqa unnamed-task
2020-12-05 17:43:25 +00:00
name : container-engine/crictl
2021-01-09 22:21:10 +00:00
# you can sometimes end up in a state where everything is installed
# but containerd was not started / enabled
- name : flush handlers
meta : flush_handlers
- name : ensure containerd is started and enabled
service :
name : containerd
enabled : yes
state : started