132 lines
3.7 KiB
YAML
132 lines
3.7 KiB
YAML
---
|
|
# ansible/tasks/kubernetes/install-containerd.yml
|
|
|
|
- name: Create work directory for containerd installation
|
|
file:
|
|
path: "{{ containerd_work_dir }}"
|
|
state: directory
|
|
mode: '0755'
|
|
|
|
- name: Download containerd tarball
|
|
get_url:
|
|
url: "https://github.com/containerd/containerd/releases/download/v{{ containerd_version }}/containerd-{{ containerd_version }}-linux-{{ containerd_arch }}.tar.gz"
|
|
dest: "{{ containerd_work_dir }}/containerd.tar.gz"
|
|
checksum: "{{ containerd_checksum }}"
|
|
mode: '0644'
|
|
|
|
- name: Extract containerd binaries to install directory
|
|
unarchive:
|
|
src: "{{ containerd_work_dir }}/containerd.tar.gz"
|
|
dest: "{{ containerd_install_root }}"
|
|
remote_src: yes
|
|
|
|
- name: Create containerd config directory
|
|
file:
|
|
path: "{{ containerd_config_root }}"
|
|
state: directory
|
|
mode: '0755'
|
|
|
|
- name: Detect if containerd is already installed
|
|
stat:
|
|
path: "{{ containerd_binary_path }}/containerd"
|
|
register: containerd_binary
|
|
|
|
- name: Generate default containerd configuration
|
|
command: "{{ containerd_binary_path }}/containerd config default"
|
|
register: default_config
|
|
changed_when: false
|
|
when: containerd_binary.stat.exists
|
|
|
|
- name: Ensure containerd group exists
|
|
group:
|
|
name: "{{ containerd_group }}"
|
|
system: yes
|
|
state: present
|
|
|
|
- name: Get containerd group GID
|
|
shell: "getent group {{ containerd_group }} | cut -d: -f3"
|
|
register: containerd_gid_cmd
|
|
changed_when: false
|
|
|
|
- name: Write containerd configuration file
|
|
copy:
|
|
content: "{{ default_config.stdout }}"
|
|
dest: "{{ containerd_config_root }}/config.toml"
|
|
mode: '0644'
|
|
when: containerd_binary.stat.exists and default_config.stdout is defined
|
|
register: config_written
|
|
|
|
- name: Update containerd config for SystemdCgroup
|
|
replace:
|
|
path: "{{ containerd_config_root }}/config.toml"
|
|
regexp: 'SystemdCgroup = false'
|
|
replace: 'SystemdCgroup = true'
|
|
when: config_written.changed
|
|
notify: Restart containerd
|
|
|
|
- name: Update containerd config for Kubernetes sandbox image
|
|
lineinfile:
|
|
path: "{{ containerd_config_root }}/config.toml"
|
|
regexp: '(\s*)sandbox_image = ".*"'
|
|
line: '\1sandbox_image = "registry.k8s.io/pause:3.10"'
|
|
backrefs: yes
|
|
when: config_written.changed
|
|
notify: Restart containerd
|
|
|
|
- name: Update containerd config for GRPC socket group (gid)
|
|
replace:
|
|
path: "{{ containerd_config_root }}/config.toml"
|
|
regexp: '^(\s*gid\s*=\s*)0'
|
|
replace: '\g<1>{{ containerd_gid_cmd.stdout }}'
|
|
when: config_written.changed
|
|
notify: Restart containerd
|
|
|
|
- name: Create containerd systemd service file
|
|
copy:
|
|
dest: "{{ containerd_systemd_root }}/containerd.service"
|
|
mode: '0644'
|
|
content: |
|
|
[Unit]
|
|
Description=containerd container runtime
|
|
Documentation=https://containerd.io
|
|
After=network.target network-online.target
|
|
|
|
[Service]
|
|
ExecStart={{ containerd_binary_path }}/containerd --config {{ containerd_config_root }}/config.toml
|
|
Restart=always
|
|
RestartSec=5
|
|
Delegate=yes
|
|
KillMode=process
|
|
OOMScoreAdjust=-999
|
|
LimitNOFILE=1048576
|
|
LimitNPROC=infinity
|
|
LimitCORE=infinity
|
|
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
notify: Restart containerd
|
|
|
|
- name: Add current user to containerd group
|
|
user:
|
|
name: "{{ ansible_user }}"
|
|
groups: "{{ containerd_group }}"
|
|
append: yes
|
|
|
|
- name: Reload systemd daemon
|
|
systemd:
|
|
daemon_reload: yes
|
|
|
|
- name: Enable and start containerd service
|
|
systemd:
|
|
name: containerd
|
|
enabled: yes
|
|
state: started
|
|
|
|
- name: Set permissions for containerd socket
|
|
file:
|
|
path: /run/containerd/containerd.sock
|
|
owner: root
|
|
group: "{{ containerd_group }}"
|
|
mode: '0660'
|
|
when: ansible_system_vendor != 'Microsoft Corporation' # Avoid issues on WSL2
|