Update proxmox-docker-install.yml

This commit is contained in:
2025-12-13 15:07:45 +00:00
parent a22e6e3b9f
commit b94939ef45

View File

@@ -1,9 +1,10 @@
---
# 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.
# Semaphore v2
# Survey vars required: vm_ip, vm_user, vm_pass
# Target OS: Ubuntu 24.04 (noble)
# Docker install method: Ubuntu repo (docker.io)
- name: Build runtime target from Survey variables (Semaphore v2)
- name: Build runtime target from Survey variables
hosts: localhost
gather_facts: false
@@ -14,9 +15,9 @@
- vm_ip is defined
- vm_user is defined
- vm_pass is defined
fail_msg: "Missing required vars. Supply vm_ip, vm_user, vm_pass in the Task Template Survey."
fail_msg: "Missing vm_ip, vm_user or vm_pass in Task Template Survey."
- name: Add VM as in-memory inventory host (force password SSH)
- name: Add VM as runtime host (password SSH)
ansible.builtin.add_host:
name: target_vm
groups: runtime
@@ -24,7 +25,6 @@
ansible_user: "{{ vm_user }}"
ansible_password: "{{ vm_pass }}"
ansible_become: true
ansible_become_method: sudo
ansible_become_password: "{{ vm_pass }}"
ansible_ssh_common_args: >-
-o PreferredAuthentications=password
@@ -33,11 +33,11 @@
-o StrictHostKeyChecking=no
-o UserKnownHostsFile=/dev/null
- name: Show connection target
- name: Show target
ansible.builtin.debug:
msg: "Targeting {{ vm_user }}@{{ vm_ip }} using PASSWORD SSH"
msg: "Targeting {{ vm_user }}@{{ vm_ip }}"
- name: Install Docker on chosen VM (Ubuntu repo method)
- name: Install Docker on VM (Ubuntu Noble)
hosts: runtime
become: true
gather_facts: true
@@ -47,8 +47,7 @@
ansible.builtin.apt:
update_cache: true
# Enable universe (often needed on minimal/cloud images)
- name: Ensure universe repository is enabled (Ubuntu)
- name: Ensure universe repo is enabled
ansible.builtin.apt_repository:
repo: "deb http://archive.ubuntu.com/ubuntu {{ ansible_distribution_release }} universe"
state: present
@@ -58,47 +57,37 @@
ansible.builtin.apt:
update_cache: true
- name: Install Docker from Ubuntu repositories
- name: Install Docker packages (Ubuntu repo)
ansible.builtin.apt:
name:
- docker.io
- containerd
- docker-compose-v2
state: present
update_cache: true
- 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: Show units found (debug)
ansible.builtin.debug:
var: docker_units.stdout_lines
- name: Enable and start containerd
ansible.builtin.systemd:
name: containerd
enabled: true
state: started
when: docker_units.stdout is search("containerd.service")
failed_when: false
- name: Enable and start docker
ansible.builtin.systemd:
name: docker
enabled: true
state: started
when: docker_units.stdout is search("docker.service")
failed_when: false
- 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: Verify docker binary exists
ansible.builtin.command: docker --version
register: docker_version
changed_when: false
- name: Verify docker daemon is running
ansible.builtin.command: docker info
register: docker_info
changed_when: false
- name: Add login user to docker group
ansible.builtin.user:
@@ -106,20 +95,14 @@
groups: docker
append: true
- name: Docker version
ansible.builtin.command: docker --version
register: docker_version
changed_when: false
- name: Docker Compose v2 version
- name: Verify docker compose
ansible.builtin.command: docker compose version
register: compose_version
changed_when: false
failed_when: false
- name: Print versions
- name: Final status
ansible.builtin.debug:
msg:
- "{{ docker_version.stdout }}"
- "{{ compose_version.stdout | default('docker compose not available') }}"
- "{{ compose_version.stdout }}"
- "Docker is installed and running"