Refactor Docker installation playbook: fix architecture detection
This commit is contained in:
@@ -1,21 +1,18 @@
|
|||||||
---
|
---
|
||||||
- name: Install Docker using official Docker documentation steps
|
- name: Install Docker using official Docker documentation steps
|
||||||
hosts: all
|
hosts: docker
|
||||||
become: true
|
become: true
|
||||||
|
|
||||||
vars:
|
vars:
|
||||||
# Path to store Docker's GPG keyring
|
|
||||||
docker_keyring_path: /etc/apt/keyrings/docker.asc
|
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
|
docker_repo_list_path: /etc/apt/sources.list.d/docker.list
|
||||||
|
|
||||||
tasks:
|
tasks:
|
||||||
- name: Ensure required packages for Docker APT setup are installed
|
- name: Ensure required packages are installed
|
||||||
apt:
|
apt:
|
||||||
name:
|
name:
|
||||||
- ca-certificates # Needed for HTTPS APT repos
|
- ca-certificates
|
||||||
- curl # Used to download the GPG key
|
- curl
|
||||||
state: present
|
state: present
|
||||||
update_cache: yes
|
update_cache: yes
|
||||||
|
|
||||||
@@ -25,25 +22,26 @@
|
|||||||
state: directory
|
state: directory
|
||||||
mode: "0755"
|
mode: "0755"
|
||||||
|
|
||||||
- name: Download Docker's official GPG key to keyring path
|
- name: Download Docker's official GPG key
|
||||||
get_url:
|
get_url:
|
||||||
url: https://download.docker.com/linux/ubuntu/gpg
|
url: https://download.docker.com/linux/ubuntu/gpg
|
||||||
dest: "{{ docker_keyring_path }}"
|
dest: "{{ docker_keyring_path }}"
|
||||||
mode: "0644"
|
mode: "0644"
|
||||||
|
register: docker_key_download
|
||||||
|
|
||||||
# Workaround block:
|
- name: Get native architecture (dpkg --print-architecture)
|
||||||
- name: Determine compatible Docker codename (bandage for Ubuntu 24.04 "noble")
|
command: dpkg --print-architecture
|
||||||
set_fact:
|
register: dpkg_arch_result
|
||||||
docker_codename: "{{ 'jammy' if ansible_lsb.codename == 'noble' else ansible_lsb.codename }}"
|
changed_when: false
|
||||||
|
|
||||||
- name: Add Docker APT repository using the compatible codename
|
- name: Add Docker repository to Apt sources
|
||||||
copy:
|
copy:
|
||||||
dest: "{{ docker_repo_list_path }}"
|
dest: "{{ docker_repo_list_path }}"
|
||||||
content: |
|
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
|
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
|
meta: flush_handlers
|
||||||
|
|
||||||
- name: Install Docker packages
|
- name: Install Docker packages
|
||||||
@@ -55,20 +53,9 @@
|
|||||||
- docker-buildx-plugin # Buildx plugin
|
- docker-buildx-plugin # Buildx plugin
|
||||||
- docker-compose-plugin # Compose v2 plugin
|
- docker-compose-plugin # Compose v2 plugin
|
||||||
state: present
|
state: present
|
||||||
update_cache: no # Cache is already updated by handler
|
update_cache: no # already handled by handler
|
||||||
|
|
||||||
handlers:
|
handlers:
|
||||||
- name: Update apt cache
|
- name: Update apt cache
|
||||||
apt:
|
apt:
|
||||||
update_cache: yes
|
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
|
|
||||||
# ------------------------------------------------------------
|
|
||||||
|
|||||||
Reference in New Issue
Block a user