--- - name: Install docker prerequisites package: name: "{{ item }}" state: present loop: - ca-certificates - curl - gnupg - lsb-release - name: One way to avoid apt_key once it is removed from your distro block: - name: create keyring folder file: path: /etc/apt/keyrings mode: '0755' recurse: true - name: Check if docker key already exists stat: path: /etc/apt/keyrings/docker.gpg register: docker_gpg - name: docker repo key shell: cmd: curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg when: docker_gpg.stat.exists == false - name: add docker repo | apt source ansible.builtin.apt_repository: repo: "deb [arch=amd64 signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu {{ ansible_distribution_release }} stable" state: present - name: Install docker package: name: "{{ item }}" state: present update_cache: true loop: - docker-ce - docker-ce-cli - containerd.io - docker-buildx-plugin - docker-compose-plugin ...