Update proxmox-docker-install.yml
This commit is contained in:
@@ -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)
|
- name: Build runtime target from Survey variables (Semaphore v2)
|
||||||
hosts: localhost
|
hosts: localhost
|
||||||
gather_facts: false
|
gather_facts: false
|
||||||
|
|
||||||
tasks:
|
tasks:
|
||||||
- name: Validate required inputs
|
- name: Validate required inputs
|
||||||
ansible.builtin.assert:
|
ansible.builtin.assert:
|
||||||
@@ -32,7 +37,7 @@
|
|||||||
ansible.builtin.debug:
|
ansible.builtin.debug:
|
||||||
msg: "Targeting {{ vm_user }}@{{ vm_ip }} using PASSWORD SSH"
|
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
|
hosts: runtime
|
||||||
become: true
|
become: true
|
||||||
gather_facts: true
|
gather_facts: true
|
||||||
@@ -42,8 +47,8 @@
|
|||||||
ansible.builtin.apt:
|
ansible.builtin.apt:
|
||||||
update_cache: true
|
update_cache: true
|
||||||
|
|
||||||
# Universe is required for some packages on Ubuntu minimal/cloud images
|
# Enable universe (often needed on minimal/cloud images)
|
||||||
- name: Ensure Ubuntu repositories (universe) are enabled
|
- name: Ensure universe repository is enabled (Ubuntu)
|
||||||
ansible.builtin.apt_repository:
|
ansible.builtin.apt_repository:
|
||||||
repo: "deb http://archive.ubuntu.com/ubuntu {{ ansible_distribution_release }} universe"
|
repo: "deb http://archive.ubuntu.com/ubuntu {{ ansible_distribution_release }} universe"
|
||||||
state: present
|
state: present
|
||||||
@@ -53,60 +58,47 @@
|
|||||||
ansible.builtin.apt:
|
ansible.builtin.apt:
|
||||||
update_cache: true
|
update_cache: true
|
||||||
|
|
||||||
- name: Install prerequisites
|
- name: Install Docker from Ubuntu repositories
|
||||||
ansible.builtin.apt:
|
|
||||||
name:
|
|
||||||
- ca-certificates
|
|
||||||
- curl
|
|
||||||
- gnupg
|
|
||||||
- lsb-release
|
|
||||||
state: present
|
|
||||||
|
|
||||||
- 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
|
|
||||||
changed_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: 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: 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:
|
ansible.builtin.apt:
|
||||||
name:
|
name:
|
||||||
- docker.io
|
- docker.io
|
||||||
|
- containerd
|
||||||
- docker-compose-v2
|
- docker-compose-v2
|
||||||
state: present
|
state: present
|
||||||
update_cache: true
|
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: Enable and start Docker service
|
- 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")
|
||||||
|
|
||||||
|
- name: Enable and start docker
|
||||||
ansible.builtin.systemd:
|
ansible.builtin.systemd:
|
||||||
name: docker
|
name: docker
|
||||||
enabled: true
|
enabled: true
|
||||||
state: started
|
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
|
- name: Add login user to docker group
|
||||||
ansible.builtin.user:
|
ansible.builtin.user:
|
||||||
@@ -119,19 +111,15 @@
|
|||||||
register: docker_version
|
register: docker_version
|
||||||
changed_when: false
|
changed_when: false
|
||||||
|
|
||||||
- name: Compose version (v2 if available, else v1)
|
- name: Docker Compose v2 version
|
||||||
ansible.builtin.shell: |
|
ansible.builtin.command: docker compose version
|
||||||
set -e
|
|
||||||
if docker compose version >/dev/null 2>&1; then
|
|
||||||
docker compose version
|
|
||||||
else
|
|
||||||
docker-compose --version
|
|
||||||
fi
|
|
||||||
register: compose_version
|
register: compose_version
|
||||||
changed_when: false
|
changed_when: false
|
||||||
|
failed_when: false
|
||||||
|
|
||||||
- name: Print versions
|
- name: Print versions
|
||||||
ansible.builtin.debug:
|
ansible.builtin.debug:
|
||||||
msg:
|
msg:
|
||||||
- "{{ docker_version.stdout }}"
|
- "{{ docker_version.stdout }}"
|
||||||
- "{{ compose_version.stdout }}"
|
- "{{ compose_version.stdout | default('docker compose not available') }}"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user