Refactor Docker installation playbook: fix architecture detection

This commit is contained in:
2025-07-12 12:33:41 -05:00
parent 359dd6da50
commit 9b35e0e811

View File

@@ -1,21 +1,18 @@
---
- name: Install Docker using official Docker documentation steps
hosts: all
hosts: docker
become: true
vars:
# Path to store Docker's GPG keyring
docker_keyring_path: /etc/apt/keyrings/docker.asc
# Path to store the Docker APT source list
docker_repo_list_path: /etc/apt/sources.list.d/docker.list
tasks:
- name: Ensure required packages for Docker APT setup are installed
- name: Ensure required packages are installed
apt:
name:
- ca-certificates # Needed for HTTPS APT repos
- curl # Used to download the GPG key
- ca-certificates
- curl
state: present
update_cache: yes
@@ -25,25 +22,26 @@
state: directory
mode: "0755"
- name: Download Docker's official GPG key to keyring path
- name: Download Docker's official GPG key
get_url:
url: https://download.docker.com/linux/ubuntu/gpg
dest: "{{ docker_keyring_path }}"
mode: "0644"
register: docker_key_download
# Workaround block:
- name: Determine compatible Docker codename (bandage for Ubuntu 24.04 "noble")
set_fact:
docker_codename: "{{ 'jammy' if ansible_lsb.codename == 'noble' else ansible_lsb.codename }}"
- name: Get native architecture (dpkg --print-architecture)
command: dpkg --print-architecture
register: dpkg_arch_result
changed_when: false
- name: Add Docker APT repository using the compatible codename
- name: Add Docker repository to Apt sources
copy:
dest: "{{ docker_repo_list_path }}"
content: |
deb [arch={{ ansible_architecture }} signed-by={{ docker_keyring_path }}] https://download.docker.com/linux/ubuntu {{ docker_codename }} stable
deb [arch={{ dpkg_arch_result.stdout }} signed-by={{ docker_keyring_path }}] https://download.docker.com/linux/ubuntu {{ ansible_lsb.codename }} stable
notify: Update apt cache
- name: Flush handlers to make sure apt cache is updated before install
- name: Flush handlers to update apt cache before install
meta: flush_handlers
- name: Install Docker packages
@@ -55,20 +53,9 @@
- docker-buildx-plugin # Buildx plugin
- docker-compose-plugin # Compose v2 plugin
state: present
update_cache: no # Cache is already updated by handler
update_cache: no # already handled by handler
handlers:
- name: Update apt cache
apt:
update_cache: yes
# ------------------------------------------------------------
# 📝 Optional: Revert this when Docker supports Ubuntu 24.04 natively
# Just replace the repo setup block with the following:
# - name: Add Docker APT repository using native codename
# copy:
# dest: "{{ docker_repo_list_path }}"
# content: |
# deb [arch={{ ansible_architecture }} signed-by={{ docker_keyring_path }}] https://download.docker.com/linux/ubuntu {{ ansible_lsb.codename }} stable
# notify: Update apt cache
# ------------------------------------------------------------