Update proxmox-docker-install.yml

This commit is contained in:
2025-12-13 14:32:04 +00:00
parent f06507f72f
commit 7a711b5550

View File

@@ -1,84 +1,57 @@
--- ---
# Play 1: runs on the Semaphore host (localhost) and creates the target VM in-memory
- 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:
that: that:
- vm_ip is defined - vm_ip is defined
- vm_user is defined fail_msg: "Missing vm_ip in Survey."
- vm_pass is defined
fail_msg: "Missing required vars. You must supply vm_ip, vm_user, vm_pass in the Task Template Survey."
- name: Add VM as in-memory inventory host (force password SSH) - name: Add VM as in-memory inventory host
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 }}" # user/pass will come from Semaphore credentials
ansible_password: "{{ vm_pass }}"
ansible_become: true
ansible_become_method: sudo
ansible_become_password: "{{ vm_pass }}"
ansible_ssh_common_args: >- ansible_ssh_common_args: >-
-o PreferredAuthentications=password -o PreferredAuthentications=password
-o PubkeyAuthentication=no -o PubkeyAuthentication=no
-o IdentitiesOnly=yes
-o StrictHostKeyChecking=no -o StrictHostKeyChecking=no
-o UserKnownHostsFile=/dev/null -o UserKnownHostsFile=/dev/null
- name: Show connection target - name: Show connection target
ansible.builtin.debug: ansible.builtin.debug:
msg: "Targeting {{ vm_user }}@{{ vm_ip }} using PASSWORD SSH" msg: "Targeting {{ vm_ip }} using PASSWORD SSH (credentials from Semaphore inventory)"
# Play 2: connects to the VM you selected and installs Docker
- name: Install Docker on chosen VM
hosts: runtime
become: true
gather_facts: true
tasks: - name: Get system architecture
- name: Update apt cache ansible.builtin.command: dpkg --print-architecture
ansible.builtin.apt: register: deb_arch
update_cache: true changed_when: false
- name: Install prerequisites - name: Download Docker GPG key
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: 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.gpg
mode: "0644" mode: "0644"
- name: Add Docker apt repository (amd64) - name: Add Docker apt repository
ansible.builtin.apt_repository: ansible.builtin.apt_repository:
repo: >- repo: >-
deb [arch=amd64 signed-by=/etc/apt/keyrings/docker.asc] deb [arch={{ deb_arch.stdout }} signed-by=/etc/apt/keyrings/docker.gpg]
https://download.docker.com/linux/ubuntu https://download.docker.com/linux/ubuntu
{{ ansible_distribution_release }} stable {{ 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 Docker repo
ansible.builtin.apt: ansible.builtin.apt:
update_cache: true update_cache: yes
- name: Install Docker engine and plugins - name: Install Docker engine and plugins
ansible.builtin.apt: ansible.builtin.apt:
name: name:
- docker-ce - docker-ce
@@ -87,32 +60,3 @@
- docker-buildx-plugin - docker-buildx-plugin
- docker-compose-plugin - docker-compose-plugin
state: present state: present
- name: Enable and start Docker
ansible.builtin.systemd:
name: docker
enabled: true
state: started
- 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 }}"