You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

143 lines
4.5 KiB

  1. ---
  2. - name: Fail containerd setup if distribution is not supported
  3. fail:
  4. msg: "{{ ansible_distribution }} is not supported by containerd."
  5. when:
  6. - not (allow_unsupported_distribution_setup | default(false)) and (ansible_distribution not in containerd_supported_distributions)
  7. - name: Containerd | Remove any package manager controlled containerd package
  8. package:
  9. name: "{{ containerd_package }}"
  10. state: absent
  11. when:
  12. - not (is_ostree or (ansible_distribution == "Flatcar Container Linux by Kinvolk") or (ansible_distribution == "Flatcar"))
  13. - name: Containerd | Remove containerd repository
  14. file:
  15. path: "{{ yum_repo_dir }}/containerd.repo"
  16. state: absent
  17. when:
  18. - ansible_os_family in ['RedHat']
  19. - name: Containerd | Remove containerd repository
  20. apt_repository:
  21. repo: "{{ item }}"
  22. state: absent
  23. with_items: "{{ containerd_repo_info.repos }}"
  24. when: ansible_pkg_mgr == 'apt'
  25. - name: Containerd | Download containerd
  26. include_tasks: "../../../download/tasks/download_file.yml"
  27. vars:
  28. download: "{{ download_defaults | combine(downloads.containerd) }}"
  29. - name: Containerd | Unpack containerd archive
  30. unarchive:
  31. src: "{{ downloads.containerd.dest }}"
  32. dest: "{{ containerd_bin_dir }}"
  33. mode: "0755"
  34. remote_src: true
  35. extra_opts:
  36. - --strip-components=1
  37. notify: Restart containerd
  38. - name: Containerd | Remove orphaned binary
  39. file:
  40. path: "/usr/bin/{{ item }}"
  41. state: absent
  42. when:
  43. - containerd_bin_dir != "/usr/bin"
  44. - not (is_ostree or (ansible_distribution == "Flatcar Container Linux by Kinvolk") or (ansible_distribution == "Flatcar"))
  45. ignore_errors: true # noqa ignore-errors
  46. with_items:
  47. - containerd
  48. - containerd-shim
  49. - containerd-shim-runc-v1
  50. - containerd-shim-runc-v2
  51. - ctr
  52. - name: Containerd | Generate systemd service for containerd
  53. template:
  54. src: containerd.service.j2
  55. dest: /etc/systemd/system/containerd.service
  56. mode: "0644"
  57. validate: "sh -c '[ -f /usr/bin/systemd/system/factory-reset.target ] || exit 0 && systemd-analyze verify %s:containerd.service'"
  58. # FIXME: check that systemd version >= 250 (factory-reset.target was introduced in that release)
  59. # Remove once we drop support for systemd < 250
  60. notify: Restart containerd
  61. - name: Containerd | Ensure containerd directories exist
  62. file:
  63. dest: "{{ item }}"
  64. state: directory
  65. mode: "0755"
  66. owner: root
  67. group: root
  68. with_items:
  69. - "{{ containerd_systemd_dir }}"
  70. - "{{ containerd_cfg_dir }}"
  71. - "{{ containerd_storage_dir }}"
  72. - "{{ containerd_state_dir }}"
  73. - name: Containerd | Write containerd proxy drop-in
  74. template:
  75. src: http-proxy.conf.j2
  76. dest: "{{ containerd_systemd_dir }}/http-proxy.conf"
  77. mode: "0644"
  78. notify: Restart containerd
  79. when: http_proxy is defined or https_proxy is defined
  80. - name: Containerd | Generate default base_runtime_spec
  81. register: ctr_oci_spec
  82. command: "{{ containerd_bin_dir }}/ctr oci spec"
  83. check_mode: false
  84. changed_when: false
  85. - name: Containerd | Store generated default base_runtime_spec
  86. set_fact:
  87. containerd_default_base_runtime_spec: "{{ ctr_oci_spec.stdout | from_json }}"
  88. - name: Containerd | Write base_runtime_specs
  89. copy:
  90. content: "{{ item.value }}"
  91. dest: "{{ containerd_cfg_dir }}/{{ item.key }}"
  92. owner: "root"
  93. mode: "0644"
  94. with_dict: "{{ containerd_base_runtime_specs | default({}) }}"
  95. notify: Restart containerd
  96. - name: Containerd | Copy containerd config file
  97. template:
  98. src: config.toml.j2
  99. dest: "{{ containerd_cfg_dir }}/config.toml"
  100. owner: "root"
  101. mode: "0640"
  102. notify: Restart containerd
  103. - name: Containerd | Configure containerd registries
  104. when: containerd_registries_mirrors is defined
  105. block:
  106. - name: Containerd | Create registry directories
  107. file:
  108. path: "{{ containerd_cfg_dir }}/certs.d/{{ item.prefix }}"
  109. state: directory
  110. mode: "0755"
  111. loop: "{{ containerd_registries_mirrors }}"
  112. - name: Containerd | Write hosts.toml file
  113. template:
  114. src: hosts.toml.j2
  115. dest: "{{ containerd_cfg_dir }}/certs.d/{{ item.prefix }}/hosts.toml"
  116. mode: "0640"
  117. loop: "{{ containerd_registries_mirrors }}"
  118. # you can sometimes end up in a state where everything is installed
  119. # but containerd was not started / enabled
  120. - name: Containerd | Flush handlers
  121. meta: flush_handlers
  122. - name: Containerd | Ensure containerd is started and enabled
  123. systemd_service:
  124. name: containerd
  125. daemon_reload: true
  126. enabled: true
  127. state: started