summaryrefslogtreecommitdiff
path: root/roles/containerd/tasks/main.yml
blob: 5955d39ed5df0be37714990e5685ed187f908f0f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
---
- name: prepare storage volume for /var/lib/containerd
  when: containerd_storage is defined
  vars:
    storage_volume: "{{ containerd_storage | combine({'dest': '/var/lib/containerd'}) }}"
  include_role:
    name: "storage/{{ containerd_storage.type }}/volume"

- name: create child-dataset for zfs-snapshotter
  when: "containerd_storage is defined and containerd_storage.type == 'zfs'"
  zfs:
    name: "{{ containerd_storage.pool }}/{{ containerd_storage.name }}/io.containerd.snapshotter.v1.zfs"
    state: present

- name: prepare package provider
  when: containerd_pkg_provider != 'distro'
  include_role:
    name: "apt-repo/{{ containerd_pkg_provider }}"

- name: generate apt pin file for containerd package
  when: containerd_pkg_version is defined
  copy:
    dest: "/etc/apt/preferences.d/{{ containerd_pkg_name }}.pref"
    content: |
      Package: {{ containerd_pkg_name }}
      Pin: version {{ containerd_pkg_version }}
      Pin-Priority: 1001

- name: remove apt pin file for containerd package
  when: containerd_pkg_version is not defined
  file:
    path: "/etc/apt/preferences.d/{{ containerd_pkg_name }}.pref"
    state: absent

- name: install containerd
  apt:
    name: "{{ containerd_pkg_name }}{% if containerd_pkg_version is defined %}={{ containerd_pkg_version }}{% endif %}"
    state: present
    allow_downgrade: yes

- name: fetch containerd default config
  check_mode: no
  command: containerd config default
  register: containerd_config_default
  changed_when: false

- name: fetch containerd default config
  copy:
    content: "{{ containerd_config_default.stdout | from_toml | combine(containerd_config, recursive=True) | to_toml }}\n"
    dest: /etc/containerd/config.toml
  notify: restart containerd

- name: start and enable containerd
  service:
    name: containerd
    enabled: true
    state: started