Refactor Docker installation playbook: add fix for noble numbat
This commit is contained in:
@@ -1,18 +1,21 @@
|
|||||||
---
|
---
|
||||||
- name: Install Docker using official Docker documentation steps
|
- name: Install Docker using official Docker documentation steps
|
||||||
hosts: docker
|
hosts: all
|
||||||
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 are installed
|
- name: Ensure required packages for Docker APT setup are installed
|
||||||
apt:
|
apt:
|
||||||
name:
|
name:
|
||||||
- ca-certificates
|
- ca-certificates # Needed for HTTPS APT repos
|
||||||
- curl
|
- curl # Used to download the GPG key
|
||||||
state: present
|
state: present
|
||||||
update_cache: yes
|
update_cache: yes
|
||||||
|
|
||||||
@@ -22,34 +25,50 @@
|
|||||||
state: directory
|
state: directory
|
||||||
mode: "0755"
|
mode: "0755"
|
||||||
|
|
||||||
- name: Download Docker's official GPG key
|
- name: Download Docker's official GPG key to keyring path
|
||||||
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"
|
||||||
|
|
||||||
- name: Add Docker repository to Apt sources
|
# 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: Add Docker APT repository using the compatible codename
|
||||||
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 {{ ansible_lsb.codename }} stable
|
deb [arch={{ ansible_architecture }} signed-by={{ docker_keyring_path }}] https://download.docker.com/linux/ubuntu {{ docker_codename }} stable
|
||||||
notify: Update apt cache
|
notify: Update apt cache
|
||||||
|
|
||||||
- name: Flush handlers to update apt cache before installing Docker
|
- name: Flush handlers to make sure apt cache is updated before install
|
||||||
meta: flush_handlers
|
meta: flush_handlers
|
||||||
|
|
||||||
- name: Install Docker packages
|
- name: Install Docker packages
|
||||||
apt:
|
apt:
|
||||||
name:
|
name:
|
||||||
- docker-ce
|
- docker-ce # Core Docker engine
|
||||||
- docker-ce-cli
|
- docker-ce-cli # CLI tool
|
||||||
- containerd.io
|
- containerd.io # Container runtime
|
||||||
- docker-buildx-plugin
|
- docker-buildx-plugin # Buildx plugin
|
||||||
- docker-compose-plugin
|
- docker-compose-plugin # Compose v2 plugin
|
||||||
state: present
|
state: present
|
||||||
update_cache: no # Already handled
|
update_cache: no # Cache is already updated 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