Update proxmox-docker-install.yml
This commit is contained in:
@@ -1,20 +1,28 @@
|
||||
---
|
||||
# Play 1: runs locally on the Semaphore host and creates a runtime target
|
||||
- name: Build runtime target from Survey variables (Semaphore v2)
|
||||
hosts: localhost
|
||||
gather_facts: false
|
||||
|
||||
tasks:
|
||||
- name: Validate required inputs
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- vm_ip is defined
|
||||
fail_msg: "Missing vm_ip in Survey."
|
||||
- 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."
|
||||
|
||||
- name: Add VM as in-memory inventory host
|
||||
- name: Add VM as in-memory inventory host (force password SSH)
|
||||
ansible.builtin.add_host:
|
||||
name: target_vm
|
||||
groups: runtime
|
||||
ansible_host: "{{ vm_ip }}"
|
||||
# user/pass will come from Semaphore credentials
|
||||
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
|
||||
-o PubkeyAuthentication=no
|
||||
@@ -24,21 +32,46 @@
|
||||
|
||||
- name: Show connection target
|
||||
ansible.builtin.debug:
|
||||
msg: "Targeting {{ vm_ip }} using PASSWORD SSH (credentials from Semaphore inventory)"
|
||||
msg: "Targeting {{ vm_user }}@{{ vm_ip }} using PASSWORD SSH"
|
||||
|
||||
# Play 2: connects to the chosen VM and installs Docker
|
||||
- name: Install Docker on chosen VM
|
||||
hosts: runtime
|
||||
become: true
|
||||
gather_facts: true
|
||||
|
||||
- name: Get system architecture
|
||||
tasks:
|
||||
- name: Update apt cache
|
||||
ansible.builtin.apt:
|
||||
update_cache: true
|
||||
|
||||
- name: Install prerequisites
|
||||
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
|
||||
- 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
|
||||
- name: Add Docker apt repository
|
||||
ansible.builtin.apt_repository:
|
||||
repo: >-
|
||||
deb [arch={{ deb_arch.stdout }} signed-by=/etc/apt/keyrings/docker.gpg]
|
||||
@@ -47,11 +80,12 @@
|
||||
state: present
|
||||
filename: docker
|
||||
|
||||
- name: Update apt cache after Docker repo
|
||||
- name: Update apt cache after adding Docker repo
|
||||
ansible.builtin.apt:
|
||||
update_cache: yes
|
||||
update_cache: true
|
||||
|
||||
- name: Install Docker engine and plugins
|
||||
# If docker-ce still isn't available on some releases/arches, we fall back to docker.io
|
||||
- name: Try install Docker CE + plugins (preferred)
|
||||
ansible.builtin.apt:
|
||||
name:
|
||||
- docker-ce
|
||||
@@ -60,3 +94,41 @@
|
||||
- docker-buildx-plugin
|
||||
- docker-compose-plugin
|
||||
state: present
|
||||
register: docker_ce_install
|
||||
ignore_errors: true
|
||||
|
||||
- name: Fallback to Ubuntu docker.io if Docker CE not available
|
||||
ansible.builtin.apt:
|
||||
name:
|
||||
- docker.io
|
||||
- docker-compose-plugin
|
||||
state: present
|
||||
when: docker_ce_install is failed
|
||||
|
||||
- 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: Docker version
|
||||
ansible.builtin.command: docker --version
|
||||
register: docker_version
|
||||
changed_when: false
|
||||
|
||||
- name: 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 }}"
|
||||
|
||||
Reference in New Issue
Block a user