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)
|
- 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
|
||||||
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:
|
ansible.builtin.add_host:
|
||||||
name: target_vm
|
name: target_vm
|
||||||
groups: runtime
|
groups: runtime
|
||||||
ansible_host: "{{ vm_ip }}"
|
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: >-
|
ansible_ssh_common_args: >-
|
||||||
-o PreferredAuthentications=password
|
-o PreferredAuthentications=password
|
||||||
-o PubkeyAuthentication=no
|
-o PubkeyAuthentication=no
|
||||||
@@ -24,39 +32,103 @@
|
|||||||
|
|
||||||
- name: Show connection target
|
- name: Show connection target
|
||||||
ansible.builtin.debug:
|
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:
|
||||||
ansible.builtin.command: dpkg --print-architecture
|
- name: Update apt cache
|
||||||
register: deb_arch
|
ansible.builtin.apt:
|
||||||
changed_when: false
|
update_cache: true
|
||||||
|
|
||||||
- name: Download Docker GPG key
|
- name: Install prerequisites
|
||||||
ansible.builtin.get_url:
|
ansible.builtin.apt:
|
||||||
url: https://download.docker.com/linux/ubuntu/gpg
|
name:
|
||||||
dest: /etc/apt/keyrings/docker.gpg
|
- ca-certificates
|
||||||
mode: "0644"
|
- curl
|
||||||
|
- gnupg
|
||||||
|
- lsb-release
|
||||||
|
state: present
|
||||||
|
|
||||||
- name: Add Docker apt repository
|
- name: Ensure /etc/apt/keyrings exists
|
||||||
ansible.builtin.apt_repository:
|
ansible.builtin.file:
|
||||||
repo: >-
|
path: /etc/apt/keyrings
|
||||||
deb [arch={{ deb_arch.stdout }} signed-by=/etc/apt/keyrings/docker.gpg]
|
state: directory
|
||||||
https://download.docker.com/linux/ubuntu
|
mode: "0755"
|
||||||
{{ ansible_distribution_release }} stable
|
|
||||||
state: present
|
|
||||||
filename: docker
|
|
||||||
|
|
||||||
- name: Update apt cache after Docker repo
|
- name: Get Debian architecture (amd64/arm64/etc)
|
||||||
ansible.builtin.apt:
|
ansible.builtin.command: dpkg --print-architecture
|
||||||
update_cache: yes
|
register: deb_arch
|
||||||
|
changed_when: false
|
||||||
|
|
||||||
- name: Install Docker engine and plugins
|
- name: Download Docker GPG key (keyring)
|
||||||
ansible.builtin.apt:
|
ansible.builtin.get_url:
|
||||||
name:
|
url: https://download.docker.com/linux/ubuntu/gpg
|
||||||
- docker-ce
|
dest: /etc/apt/keyrings/docker.gpg
|
||||||
- docker-ce-cli
|
mode: "0644"
|
||||||
- containerd.io
|
|
||||||
- docker-buildx-plugin
|
- name: Add Docker apt repository
|
||||||
- docker-compose-plugin
|
ansible.builtin.apt_repository:
|
||||||
state: present
|
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
|
||||||
|
|
||||||
|
# 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
|
||||||
|
- docker-ce-cli
|
||||||
|
- containerd.io
|
||||||
|
- 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