Update proxmox-docker-install.yml

This commit is contained in:
2025-12-13 15:04:09 +00:00
parent 45e1aafb42
commit a22e6e3b9f

View File

@@ -1,7 +1,12 @@
---
# Semaphore v2: prompts via Survey for vm_ip, vm_user, vm_pass
# Installs Docker on Ubuntu 24.04 (noble) using Ubuntu repo packages (docker.io + docker-compose-v2)
# Includes strong checks so failures are obvious.
- name: Build runtime target from Survey variables (Semaphore v2)
hosts: localhost
gather_facts: false
tasks:
- name: Validate required inputs
ansible.builtin.assert:
@@ -32,7 +37,7 @@
ansible.builtin.debug:
msg: "Targeting {{ vm_user }}@{{ vm_ip }} using PASSWORD SSH"
- name: Install Docker on chosen VM
- name: Install Docker on chosen VM (Ubuntu repo method)
hosts: runtime
become: true
gather_facts: true
@@ -42,8 +47,8 @@
ansible.builtin.apt:
update_cache: true
# Universe is required for some packages on Ubuntu minimal/cloud images
- name: Ensure Ubuntu repositories (universe) are enabled
# Enable universe (often needed on minimal/cloud images)
- name: Ensure universe repository is enabled (Ubuntu)
ansible.builtin.apt_repository:
repo: "deb http://archive.ubuntu.com/ubuntu {{ ansible_distribution_release }} universe"
state: present
@@ -53,60 +58,47 @@
ansible.builtin.apt:
update_cache: true
- name: Install prerequisites
- name: Install Docker from Ubuntu repositories
ansible.builtin.apt:
name:
- ca-certificates
- curl
- gnupg
- lsb-release
- docker.io
- containerd
- docker-compose-v2
state: present
update_cache: true
- name: Ensure /etc/apt/keyrings exists
ansible.builtin.file:
path: /etc/apt/keyrings
state: directory
mode: "0755"
- name: Get Debian architecture (amd64/arm64/etc)
ansible.builtin.command: dpkg --print-architecture
register: deb_arch
- name: List docker/containerd systemd units (debug)
ansible.builtin.command: systemctl list-unit-files | grep -E '^(docker|containerd)\.service'
register: docker_units
changed_when: false
failed_when: false
- name: Download Docker GPG key (keyring)
ansible.builtin.get_url:
url: https://download.docker.com/linux/ubuntu/gpg
dest: /etc/apt/keyrings/docker.gpg
mode: "0644"
- name: Show units found (debug)
ansible.builtin.debug:
var: docker_units.stdout_lines
- name: Add Docker apt repository
ansible.builtin.apt_repository:
repo: >-
deb [arch={{ deb_arch.stdout }} signed-by=/etc/apt/keyrings/docker.gpg]
https://download.docker.com/linux/ubuntu
{{ ansible_distribution_release }} stable
state: present
filename: docker
- name: Enable and start containerd
ansible.builtin.systemd:
name: containerd
enabled: true
state: started
when: docker_units.stdout is search("containerd.service")
- name: Update apt cache after adding Docker repo
ansible.builtin.apt:
update_cache: true
# ---- Install path A: Docker CE (preferred) ----
- name: Install Docker from Ubuntu repo (Ubuntu 24.04 noble)
ansible.builtin.apt:
name:
- docker.io
- docker-compose-v2
state: present
update_cache: true
- name: Enable and start Docker service
- name: Enable and start docker
ansible.builtin.systemd:
name: docker
enabled: true
state: started
when: docker_units.stdout is search("docker.service")
- name: Fail clearly if docker.service is missing
ansible.builtin.fail:
msg: >
docker.service not found after installation.
Run on VM: dpkg -l | grep -E 'docker|containerd' ;
systemctl list-unit-files | grep -E 'docker|containerd' ;
which docker
when: docker_units.stdout is not search("docker.service")
- name: Add login user to docker group
ansible.builtin.user:
@@ -119,19 +111,15 @@
register: docker_version
changed_when: false
- name: Compose version (v2 if available, else v1)
ansible.builtin.shell: |
set -e
if docker compose version >/dev/null 2>&1; then
docker compose version
else
docker-compose --version
fi
- name: Docker Compose v2 version
ansible.builtin.command: docker compose version
register: compose_version
changed_when: false
failed_when: false
- name: Print versions
ansible.builtin.debug:
msg:
- "{{ docker_version.stdout }}"
- "{{ compose_version.stdout }}"
- "{{ compose_version.stdout | default('docker compose not available') }}"