Update proxmox-docker-install.yml

This commit is contained in:
2025-12-13 13:04:15 +00:00
parent f04d00b652
commit 2c038bb0b4

View File

@@ -1,28 +1,17 @@
---
# Play 1: just normalize vars (no prompt here)
- name: Receive node and VMID
hosts: localhost
gather_facts: false
tasks:
- name: Store chosen values as facts on localhost
ansible.builtin.set_fact:
chosen_node: "{{ target_node }}"
chosen_vmid: "{{ target_vmid }}"
# Play 2: run on the chosen node and install Docker
- name: Install Docker and Docker Compose on chosen node
hosts: "{{ hostvars['localhost'].chosen_node }}"
- name: Install Docker on chosen VM
hosts: all
become: true
gather_facts: true
vars:
vmid: "{{ hostvars['localhost'].chosen_vmid }}"
node: "{{ target_node | default('n/a') }}"
vmid: "{{ target_vmid | default('n/a') }}"
tasks:
- name: Show which node and VMID are selected
ansible.builtin.debug:
msg: "Installing Docker on node {{ inventory_hostname }} for VMID {{ vmid }}"
msg: "Installing Docker for node={{ node }} vmid={{ vmid }} host={{ inventory_hostname }}"
- name: Update apt cache
ansible.builtin.apt:
@@ -30,11 +19,7 @@
- name: Install prerequisites
ansible.builtin.apt:
name:
- ca-certificates
- curl
- gnupg
- lsb-release
name: [ca-certificates, curl, gnupg, lsb-release]
state: present
- name: Create keyrings directory
@@ -51,7 +36,7 @@
- name: Add Docker repository
ansible.builtin.apt_repository:
repo: "deb [arch={{ ansible_architecture }} signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu {{ ansible_distribution_release }} stable"
repo: "deb [arch=amd64 signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu {{ ansible_distribution_release }} stable"
state: present
filename: docker
@@ -77,22 +62,6 @@
- name: Add SSH user to docker group
ansible.builtin.user:
name: "{{ ansible_user }}"
name: "{{ ansible_user_id }}"
groups: docker
append: yes
- name: Show Docker versions
ansible.builtin.command: docker version
register: docker_version
changed_when: false
- name: Show Docker Compose version
ansible.builtin.command: docker compose version
register: docker_compose_version
changed_when: false
- name: Print Docker info
ansible.builtin.debug:
msg:
- "Docker version: {{ docker_version.stdout_lines | default([]) }}"
- "Docker Compose: {{ docker_compose_version.stdout_lines | default([]) }}"
append: yes