Merge pull request #97 from svc-design/codex/add-docker-support-for-multiple-os

Add playbook to install Docker on supported hosts
This commit is contained in:
shenlan 2025-12-01 20:32:45 +08:00 committed by GitHub
commit 0dd23091ac
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 114 additions and 0 deletions

View File

@ -0,0 +1,7 @@
---
# Default Docker repository channel
# Available options: stable, test, nightly
# Default is stable
# The channel used when configuring Docker repositories.
docker_channel: stable

View File

@ -0,0 +1,3 @@
---
dependencies:
- role: common

View File

@ -0,0 +1,99 @@
---
- name: Detect supported platform
ansible.builtin.set_fact:
docker_platform: >-
{{
'ubuntu' if ansible_distribution == 'Ubuntu' and ansible_distribution_version in ['22.04', '24.04']
else 'rocky' if ansible_distribution == 'Rocky' and (ansible_distribution_major_version | int) in [8, 9, 10]
else 'unsupported'
}}
- name: Determine repository architecture
ansible.builtin.set_fact:
docker_repo_arch: "{{ 'amd64' if ansible_architecture == 'x86_64' else ansible_architecture }}"
when: ansible_distribution == 'Ubuntu'
- name: Ensure platform is supported
ansible.builtin.assert:
that: docker_platform != 'unsupported'
fail_msg: >-
Docker installation is only supported on Ubuntu 22.04/24.04 and Rocky Linux 8/9/10.
- name: Install Docker on Ubuntu
when: docker_platform == 'ubuntu'
block:
- name: Install required packages
ansible.builtin.apt:
name:
- ca-certificates
- curl
- gnupg
- lsb-release
state: present
update_cache: true
- name: Ensure apt keyring directory exists
ansible.builtin.file:
path: /etc/apt/keyrings
state: directory
mode: '0755'
- name: Add Docker GPG key
ansible.builtin.get_url:
url: https://download.docker.com/linux/ubuntu/gpg
dest: /etc/apt/keyrings/docker.asc
mode: '0644'
- name: Add Docker repository
ansible.builtin.apt_repository:
repo: >-
deb [arch={{ docker_repo_arch }} signed-by=/etc/apt/keyrings/docker.asc]
https://download.docker.com/linux/ubuntu {{ ansible_distribution_release }} {{ docker_channel }}
state: present
filename: docker
- name: Install Docker Engine packages
ansible.builtin.apt:
name:
- docker-ce
- docker-ce-cli
- containerd.io
- docker-buildx-plugin
- docker-compose-plugin
state: present
update_cache: true
- name: Install Docker on Rocky Linux
when: docker_platform == 'rocky'
block:
- name: Install required packages
ansible.builtin.package:
name:
- dnf-plugins-core
- yum-utils
state: present
- name: Configure Docker repository
ansible.builtin.yum_repository:
name: docker-ce
description: Docker CE Repository
baseurl: https://download.docker.com/linux/centos/$releasever/$basearch/{{ docker_channel }}
enabled: true
gpgcheck: true
gpgkey: https://download.docker.com/linux/centos/gpg
- name: Install Docker Engine packages
ansible.builtin.package:
name:
- docker-ce
- docker-ce-cli
- containerd.io
- docker-buildx-plugin
- docker-compose-plugin
state: present
- name: Ensure Docker service is enabled and running
ansible.builtin.service:
name: docker
state: started
enabled: true

View File

@ -0,0 +1,5 @@
- name: Setup Docker Engine
hosts: all
become: true
roles:
- roles/vhosts/docker