Update proxmox-docker-install.yml

This commit is contained in:
2025-12-13 13:59:08 +00:00
parent 8108b67b2e
commit f06507f72f

View File

@@ -1,34 +1,39 @@
--- ---
- name: Build runtime target from survey vars # Play 1: runs on the Semaphore host (localhost) and creates the target VM in-memory
- name: Build runtime target from Survey variables (Semaphore v2)
hosts: localhost hosts: localhost
gather_facts: false gather_facts: false
tasks: tasks:
- name: Fail early if required vars missing - name: Validate required inputs
ansible.builtin.assert: ansible.builtin.assert:
that: that:
- vm_ip is defined - vm_ip is defined
- vm_user is defined - vm_user is defined
- vm_pass is defined - vm_pass is defined
fail_msg: "Need vm_ip, vm_user, vm_pass (and optionally become_pass)." fail_msg: "Missing required vars. You must supply vm_ip, vm_user, vm_pass in the Task Template Survey."
- name: Add the chosen VM as an in-memory inventory host (password auth) - name: Add VM as in-memory inventory host (force password SSH)
ansible.builtin.add_host: ansible.builtin.add_host:
name: target_vm name: target_vm
groups: runtime groups: runtime
ansible_host: "{{ vm_ip }}" ansible_host: "{{ vm_ip }}"
ansible_user: "{{ vm_user }}" ansible_user: "{{ vm_user }}"
ansible_password: "{{ vm_pass }}" ansible_password: "{{ vm_pass }}"
ansible_ssh_common_args: "-o PreferredAuthentications=password -o PubkeyAuthentication=no"
# If you need sudo:
ansible_become: true ansible_become: true
ansible_become_method: sudo ansible_become_method: sudo
ansible_become_password: "{{ become_pass | default(vm_pass) }}" ansible_become_password: "{{ vm_pass }}"
ansible_ssh_common_args: >-
-o PreferredAuthentications=password
-o PubkeyAuthentication=no
-o StrictHostKeyChecking=no
-o UserKnownHostsFile=/dev/null
- name: Show what we will target - name: Show connection target
ansible.builtin.debug: ansible.builtin.debug:
msg: "Targeting {{ vm_user }}@{{ vm_ip }} with password auth" msg: "Targeting {{ vm_user }}@{{ vm_ip }} using PASSWORD SSH"
# Play 2: connects to the VM you selected and installs Docker
- name: Install Docker on chosen VM - name: Install Docker on chosen VM
hosts: runtime hosts: runtime
become: true become: true
@@ -37,7 +42,7 @@
tasks: tasks:
- name: Update apt cache - name: Update apt cache
ansible.builtin.apt: ansible.builtin.apt:
update_cache: yes update_cache: true
- name: Install prerequisites - name: Install prerequisites
ansible.builtin.apt: ansible.builtin.apt:
@@ -48,27 +53,30 @@
- lsb-release - lsb-release
state: present state: present
- name: Create keyrings directory - name: Ensure /etc/apt/keyrings exists
ansible.builtin.file: ansible.builtin.file:
path: /etc/apt/keyrings path: /etc/apt/keyrings
state: directory state: directory
mode: '0755' mode: "0755"
- name: Add Docker GPG key - name: Download Docker GPG key
ansible.builtin.get_url: ansible.builtin.get_url:
url: https://download.docker.com/linux/ubuntu/gpg url: https://download.docker.com/linux/ubuntu/gpg
dest: /etc/apt/keyrings/docker.asc dest: /etc/apt/keyrings/docker.asc
mode: '0644' mode: "0644"
- name: Add Docker repository (amd64) - name: Add Docker apt repository (amd64)
ansible.builtin.apt_repository: ansible.builtin.apt_repository:
repo: "deb [arch=amd64 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 state: present
filename: docker filename: docker
- name: Update apt cache after adding Docker repo - name: Update apt cache after adding Docker repo
ansible.builtin.apt: ansible.builtin.apt:
update_cache: yes update_cache: true
- name: Install Docker engine and plugins - name: Install Docker engine and plugins
ansible.builtin.apt: ansible.builtin.apt:
@@ -80,9 +88,31 @@
- docker-compose-plugin - docker-compose-plugin
state: present state: present
- name: Start and enable Docker service - name: Enable and start Docker
ansible.builtin.systemd: ansible.builtin.systemd:
name: docker name: docker
enabled: true
state: started state: started
enabled: yes
- name: Add login user to docker group
ansible.builtin.user:
name: "{{ ansible_user_id }}"
groups: docker
append: true
- name: Show Docker version
ansible.builtin.command: docker --version
register: docker_version
changed_when: false
- name: Show Docker Compose version
ansible.builtin.command: docker compose version
register: compose_version
changed_when: false
- name: Print versions
ansible.builtin.debug:
msg:
- "{{ docker_version.stdout }}"
- "{{ compose_version.stdout }}"