2019-06-30 05:09:20 +08:00
|
|
|
---
|
|
|
|
- name: Fail containerd setup if distribution is not supported
|
|
|
|
fail:
|
|
|
|
msg: "{{ ansible_distribution }} is not supported by containerd."
|
|
|
|
when:
|
2023-03-10 14:00:39 +08:00
|
|
|
- not (allow_unsupported_distribution_setup | default(false)) and (ansible_distribution not in containerd_supported_distributions)
|
2019-06-30 05:09:20 +08:00
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Containerd | Remove any package manager controlled containerd package
|
2021-10-20 23:47:58 +08:00
|
|
|
package:
|
|
|
|
name: "{{ containerd_package }}"
|
|
|
|
state: absent
|
|
|
|
when:
|
|
|
|
- not (is_ostree or (ansible_distribution == "Flatcar Container Linux by Kinvolk") or (ansible_distribution == "Flatcar"))
|
2019-07-11 14:46:54 +08:00
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Containerd | Remove containerd repository
|
2020-01-29 17:24:14 +08:00
|
|
|
file:
|
2021-10-20 23:47:58 +08:00
|
|
|
path: "{{ yum_repo_dir }}/containerd.repo"
|
|
|
|
state: absent
|
|
|
|
when:
|
|
|
|
- ansible_os_family in ['RedHat']
|
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Containerd | Remove containerd repository
|
2021-10-20 23:47:58 +08:00
|
|
|
apt_repository:
|
|
|
|
repo: "{{ item }}"
|
|
|
|
state: absent
|
|
|
|
with_items: "{{ containerd_repo_info.repos }}"
|
|
|
|
when: ansible_pkg_mgr == 'apt'
|
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Containerd | Download containerd
|
2021-10-20 23:47:58 +08:00
|
|
|
include_tasks: "../../../download/tasks/download_file.yml"
|
|
|
|
vars:
|
|
|
|
download: "{{ download_defaults | combine(downloads.containerd) }}"
|
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Containerd | Unpack containerd archive
|
2021-10-20 23:47:58 +08:00
|
|
|
unarchive:
|
|
|
|
src: "{{ downloads.containerd.dest }}"
|
|
|
|
dest: "{{ containerd_bin_dir }}"
|
2021-07-12 15:00:47 +08:00
|
|
|
mode: 0755
|
2021-10-20 23:47:58 +08:00
|
|
|
remote_src: yes
|
|
|
|
extra_opts:
|
|
|
|
- --strip-components=1
|
2023-07-26 22:36:22 +08:00
|
|
|
notify: Restart containerd
|
2020-01-29 17:24:14 +08:00
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Containerd | Remove orphaned binary
|
2021-11-05 22:53:53 +08:00
|
|
|
file:
|
|
|
|
path: "/usr/bin/{{ item }}"
|
|
|
|
state: absent
|
2022-03-16 04:47:48 +08:00
|
|
|
when:
|
|
|
|
- containerd_bin_dir != "/usr/bin"
|
|
|
|
- not (is_ostree or (ansible_distribution == "Flatcar Container Linux by Kinvolk") or (ansible_distribution == "Flatcar"))
|
2021-11-05 22:53:53 +08:00
|
|
|
ignore_errors: true # noqa ignore-errors
|
|
|
|
with_items:
|
|
|
|
- containerd
|
|
|
|
- containerd-shim
|
|
|
|
- containerd-shim-runc-v1
|
|
|
|
- containerd-shim-runc-v2
|
|
|
|
- ctr
|
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Containerd | Generate systemd service for containerd
|
2020-01-29 17:24:14 +08:00
|
|
|
template:
|
2021-10-20 23:47:58 +08:00
|
|
|
src: containerd.service.j2
|
|
|
|
dest: /etc/systemd/system/containerd.service
|
2021-07-12 15:00:47 +08:00
|
|
|
mode: 0644
|
2023-07-26 22:36:22 +08:00
|
|
|
notify: Restart containerd
|
2020-01-29 17:24:14 +08:00
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Containerd | Ensure containerd directories exist
|
2019-07-11 14:46:54 +08:00
|
|
|
file:
|
2021-10-20 23:47:58 +08:00
|
|
|
dest: "{{ item }}"
|
2019-07-11 14:46:54 +08:00
|
|
|
state: directory
|
|
|
|
mode: 0755
|
|
|
|
owner: root
|
|
|
|
group: root
|
2021-10-20 23:47:58 +08:00
|
|
|
with_items:
|
|
|
|
- "{{ containerd_systemd_dir }}"
|
|
|
|
- "{{ containerd_cfg_dir }}"
|
|
|
|
- "{{ containerd_storage_dir }}"
|
|
|
|
- "{{ containerd_state_dir }}"
|
2019-07-11 14:46:54 +08:00
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Containerd | Write containerd proxy drop-in
|
2021-10-20 23:47:58 +08:00
|
|
|
template:
|
|
|
|
src: http-proxy.conf.j2
|
|
|
|
dest: "{{ containerd_systemd_dir }}/http-proxy.conf"
|
|
|
|
mode: 0644
|
2023-07-26 22:36:22 +08:00
|
|
|
notify: Restart containerd
|
2021-10-20 23:47:58 +08:00
|
|
|
when: http_proxy is defined or https_proxy is defined
|
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Containerd | Generate default base_runtime_spec
|
2022-11-08 22:44:32 +08:00
|
|
|
register: ctr_oci_spec
|
|
|
|
command: "{{ containerd_bin_dir }}/ctr oci spec"
|
|
|
|
check_mode: false
|
|
|
|
changed_when: false
|
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Containerd | Store generated default base_runtime_spec
|
2022-11-08 22:44:32 +08:00
|
|
|
set_fact:
|
|
|
|
containerd_default_base_runtime_spec: "{{ ctr_oci_spec.stdout | from_json }}"
|
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Containerd | Write base_runtime_specs
|
2022-09-24 01:38:27 +08:00
|
|
|
copy:
|
|
|
|
content: "{{ item.value }}"
|
|
|
|
dest: "{{ containerd_cfg_dir }}/{{ item.key }}"
|
|
|
|
owner: "root"
|
|
|
|
mode: 0644
|
|
|
|
with_dict: "{{ containerd_base_runtime_specs | default({}) }}"
|
2023-07-26 22:36:22 +08:00
|
|
|
notify: Restart containerd
|
2022-09-24 01:38:27 +08:00
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Containerd | Copy containerd config file
|
2019-06-30 05:09:20 +08:00
|
|
|
template:
|
|
|
|
src: config.toml.j2
|
2019-07-11 14:46:54 +08:00
|
|
|
dest: "{{ containerd_cfg_dir }}/config.toml"
|
|
|
|
owner: "root"
|
2021-04-12 16:02:00 +08:00
|
|
|
mode: 0640
|
2023-07-26 22:36:22 +08:00
|
|
|
notify: Restart containerd
|
2019-06-30 05:09:20 +08:00
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Containerd | Configure containerd registries
|
2023-08-16 20:18:27 +08:00
|
|
|
when: containerd_registries_mirrors is defined
|
2023-07-26 22:36:22 +08:00
|
|
|
block:
|
2023-08-16 20:18:27 +08:00
|
|
|
- name: Containerd | Create registry directories
|
2023-02-17 12:57:39 +08:00
|
|
|
file:
|
2023-08-16 20:18:27 +08:00
|
|
|
path: "{{ containerd_cfg_dir }}/certs.d/{{ item.prefix }}"
|
2023-02-17 12:57:39 +08:00
|
|
|
state: directory
|
|
|
|
mode: 0755
|
2023-08-16 20:18:27 +08:00
|
|
|
loop: "{{ containerd_registries_mirrors }}"
|
|
|
|
- name: Containerd | Write hosts.toml file
|
|
|
|
template:
|
|
|
|
src: hosts.toml.j2
|
|
|
|
dest: "{{ containerd_cfg_dir }}/certs.d/{{ item.prefix }}/hosts.toml"
|
2023-02-17 12:57:39 +08:00
|
|
|
mode: 0640
|
2023-08-16 20:18:27 +08:00
|
|
|
loop: "{{ containerd_registries_mirrors }}"
|
2023-01-17 15:42:32 +08:00
|
|
|
|
2021-01-10 06:21:10 +08:00
|
|
|
# you can sometimes end up in a state where everything is installed
|
|
|
|
# but containerd was not started / enabled
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Containerd | Flush handlers
|
2021-01-10 06:21:10 +08:00
|
|
|
meta: flush_handlers
|
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Containerd | Ensure containerd is started and enabled
|
2022-04-29 23:39:14 +08:00
|
|
|
systemd:
|
2021-01-10 06:21:10 +08:00
|
|
|
name: containerd
|
2022-04-29 23:39:14 +08:00
|
|
|
daemon_reload: yes
|
2021-01-10 06:21:10 +08:00
|
|
|
enabled: yes
|
|
|
|
state: started
|