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.

134 lines
4.3 KiB

  1. ---
  2. - name: check if fedora coreos
  3. stat:
  4. path: /run/ostree-booted
  5. get_attributes: no
  6. get_checksum: no
  7. get_mime: no
  8. register: ostree
  9. - name: set is_ostree
  10. set_fact:
  11. is_ostree: "{{ ostree.stat.exists }}"
  12. - name: Fail containerd setup if distribution is not supported
  13. fail:
  14. msg: "{{ ansible_distribution }} is not supported by containerd."
  15. when:
  16. - not ansible_distribution in ["CentOS", "OracleLinux", "RedHat", "Ubuntu", "Debian", "Fedora", "AlmaLinux", "Amazon", "Flatcar Container Linux by Kinvolk"]
  17. - name: gather os specific variables
  18. include_vars: "{{ item }}"
  19. with_first_found:
  20. - files:
  21. - "{{ ansible_distribution|lower }}-{{ ansible_distribution_version|lower|replace('/', '_') }}.yml"
  22. - "{{ ansible_distribution|lower }}-{{ ansible_distribution_release|lower }}-{{ host_architecture }}.yml"
  23. - "{{ ansible_distribution|lower }}-{{ ansible_distribution_release|lower }}.yml"
  24. - "{{ ansible_distribution|lower }}-{{ ansible_distribution_major_version|lower|replace('/', '_') }}.yml"
  25. - "{{ ansible_distribution|lower }}-{{ host_architecture }}.yml"
  26. - "{{ ansible_distribution|lower }}.yml"
  27. - "{{ ansible_os_family|lower }}-{{ host_architecture }}.yml"
  28. - "{{ ansible_os_family|lower }}.yml"
  29. - defaults.yml
  30. paths:
  31. - ../vars
  32. skip: true
  33. tags:
  34. - facts
  35. - name: disable unified_cgroup_hierarchy in Fedora 31+
  36. command: grubby --update-kernel=ALL --args="systemd.unified_cgroup_hierarchy=0"
  37. when:
  38. - ansible_distribution == "Fedora"
  39. - (ansible_distribution_major_version | int) >= 31
  40. - ansible_proc_cmdline['systemd.unified_cgroup_hierarchy'] is not defined or ansible_proc_cmdline['systemd.unified_cgroup_hierarchy'] != '0'
  41. - not is_ostree
  42. - name: reboot in Fedora 31+
  43. reboot:
  44. when:
  45. - ansible_distribution == "Fedora"
  46. - (ansible_distribution_major_version | int) >= 31
  47. - ansible_proc_cmdline['systemd.unified_cgroup_hierarchy'] is not defined or ansible_proc_cmdline['systemd.unified_cgroup_hierarchy'] != '0'
  48. - not is_ostree
  49. - include_tasks: containerd_repo.yml
  50. when: not (is_ostree or (ansible_distribution == "Flatcar Container Linux by Kinvolk"))
  51. - name: Create containerd service systemd directory if it doesn't exist
  52. file:
  53. path: /etc/systemd/system/containerd.service.d
  54. state: directory
  55. mode: 0755
  56. - name: Write containerd proxy drop-in
  57. template:
  58. src: http-proxy.conf.j2
  59. dest: /etc/systemd/system/containerd.service.d/http-proxy.conf
  60. mode: 0644
  61. notify: restart containerd
  62. when: http_proxy is defined or https_proxy is defined
  63. - name: ensure containerd config directory
  64. file:
  65. dest: "{{ containerd_cfg_dir }}"
  66. state: directory
  67. mode: 0755
  68. owner: root
  69. group: root
  70. - name: Copy containerd config file
  71. template:
  72. src: config.toml.j2
  73. dest: "{{ containerd_cfg_dir }}/config.toml"
  74. owner: "root"
  75. mode: 0640
  76. notify: restart containerd
  77. # This is required to ensure any apt upgrade will not break kubernetes
  78. - name: Set containerd pin priority to apt_preferences on Debian family
  79. copy:
  80. content: |
  81. Package: {{ containerd_package }}
  82. Pin: version {{ containerd_version }}*
  83. Pin-Priority: 1001
  84. dest: "/etc/apt/preferences.d/containerd"
  85. owner: "root"
  86. mode: 0644
  87. when: ansible_pkg_mgr == 'apt'
  88. - name: ensure containerd packages are installed
  89. package:
  90. name: "{{ containerd_package_info.pkgs }}"
  91. state: present
  92. module_defaults:
  93. apt:
  94. update_cache: true
  95. dnf:
  96. enablerepo: "{{ containerd_package_info.enablerepo | default(omit) }}"
  97. yum:
  98. enablerepo: "{{ containerd_package_info.enablerepo | default(omit) }}"
  99. zypper:
  100. update_cache: true
  101. register: containerd_task_result
  102. until: containerd_task_result is succeeded
  103. retries: 4
  104. delay: "{{ retry_stagger | d(3) }}"
  105. notify: restart containerd
  106. when:
  107. - not (is_ostree or (ansible_distribution == "Flatcar Container Linux by Kinvolk"))
  108. - containerd_package_info.pkgs|length > 0
  109. - include_role: # noqa unnamed-task
  110. name: container-engine/crictl
  111. # you can sometimes end up in a state where everything is installed
  112. # but containerd was not started / enabled
  113. - name: flush handlers
  114. meta: flush_handlers
  115. - name: ensure containerd is started and enabled
  116. service:
  117. name: containerd
  118. enabled: yes
  119. state: started