---
- name: 配置Docker CE国内源
  yum_repository:
    name: docker-ce
    description: Docker CE Stable
    baseurl: "{{ mirror_aliyun }}/docker-ce/linux/centos/$releasever/$basearch/stable"
    gpgcheck: yes
    gpgkey: "{{ mirror_aliyun }}/docker-ce/linux/centos/gpg"
    enabled: yes
  become: yes

- name: 安装containerd
  yum:
    name: 
      - containerd.io-{{ containerd_version }}
      - containerd
    state: present
  become: yes

- name: 创建containerd配置目录
  file:
    path: /etc/containerd
    state: directory
    mode: '0755'
  become: yes

- name: 上传containerd配置文件
  copy:
    src: "{{ role_path }}/files/config.toml"
    dest: /etc/containerd/config.toml
    mode: '0644'
    backup: yes
  become: yes

- name: 上传目录配置文件
  copy:
    src: "{{ role_path }}/files/certs.d"
    dest: /etc/containerd/
    mode: '0644'
    backup: yes
  become: yes

- name: 上传crictl配置文件
  copy:
    src: "{{ role_path }}/files/crictl.yml"
    dest: /etc/crictl.yml
    mode: '0644'
  become: yes

- name: 重启containerd
  systemd:
    name: containerd
    state: restarted
    enabled: yes
    daemon_reload: yes
  become: yes

- name: 验证containerd安装
  shell: |
    ctr version
    ctr images pull docker.io/library/hello-world:latest
    ctr images ls | grep hello-world
  become: yes
  register: containerd_check
  changed_when: false

- name: 显示containerd验证结果
  debug:
    msg: "{{ containerd_check.stdout }}"

