瀏覽代碼

fix(ansible): replace deprecated apt_key with deb822_repository in docker-install-ubuntu

- Remove deprecated ansible.builtin.apt_key usage
- Replace apt_key + apt_repository with modern deb822_repository
- Add package cleanup for conflicting Docker packages
- Include missing docker-ce-cli and containerd.io components
- Update dependencies according to the current official Docker Documentation

_(NB: None of the code in this commit is AI-generated. AI has only been used to review the code and enhance the commit message.)_
Fabrizio 4 月之前
父節點
當前提交
5b01152178
共有 1 個文件被更改,包括 25 次插入15 次删除
  1. 25 15
      library/ansible/docker-install-ubuntu/main.yml.j2

+ 25 - 15
library/ansible/docker-install-ubuntu/main.yml.j2

@@ -5,32 +5,42 @@
   gather_facts: true
   gather_facts: true
 
 
   tasks:
   tasks:
-    - name: Install docker dependencies
+    - name: Remove conflicting packages
+      ansible.builtin.apt:
+        name:
+          - docker.io
+          - docker-compose
+          - docker-compose-v2
+          - docker-doc
+          - podman-docker
+          - containerd
+          - runc
+        state: absent
+
+    - name: Install docker/ansible dependencies
       ansible.builtin.apt:
       ansible.builtin.apt:
         name:
         name:
-          - apt-transport-https
           - ca-certificates
           - ca-certificates
           - curl
           - curl
-          - gnupg-agent
-          - software-properties-common
+          - python3-debian
         update_cache: true
         update_cache: true
 
 
-    - name: Add docker gpg key
-      ansible.builtin.apt_key:
-        url: https://download.docker.com/linux/ubuntu/gpg
-        state: present
-        keyring: /etc/apt/keyrings/docker.gpg
-
-    - name: Add docker repository
-      ansible.builtin.apt_repository:
-        filename: docker
-        repo: deb [arch=amd64 signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu {% verbatim %}{{ ansible_lsb.codename | lower }}{% endverbatim %} stable
-        state: present
+    - name: Add docker repository with docker key from URL
+      ansible.builtin.deb822_repository:
+        name: docker
+        types: deb
+        uris: https://download.docker.com/linux/ubuntu
+        suites: '{{ ansible_distribution_release }}'
+        components: stable
+        architectures: amd64
+        signed_by: https://download.docker.com/linux/ubuntu/gpg 
 
 
     - name: Install docker engine
     - name: Install docker engine
       ansible.builtin.apt:
       ansible.builtin.apt:
         name:
         name:
           - docker-ce
           - docker-ce
+          - docker-ce-cli
+          - containerd.io
           - docker-buildx-plugin
           - docker-buildx-plugin
           - docker-compose-plugin
           - docker-compose-plugin
         update_cache: true
         update_cache: true