Update proxmox-docker-install.yml
This commit is contained in:
@@ -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
|
||||
gather_facts: false
|
||||
|
||||
tasks:
|
||||
- name: Fail early if required vars missing
|
||||
- name: Validate required inputs
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- vm_ip is defined
|
||||
- vm_user 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:
|
||||
name: target_vm
|
||||
groups: runtime
|
||||
ansible_host: "{{ vm_ip }}"
|
||||
ansible_user: "{{ vm_user }}"
|
||||
ansible_password: "{{ vm_pass }}"
|
||||
ansible_ssh_common_args: "-o PreferredAuthentications=password -o PubkeyAuthentication=no"
|
||||
|
||||
# If you need sudo:
|
||||
ansible_become: true
|
||||
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:
|
||||
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
|
||||
hosts: runtime
|
||||
become: true
|
||||
@@ -37,7 +42,7 @@
|
||||
tasks:
|
||||
- name: Update apt cache
|
||||
ansible.builtin.apt:
|
||||
update_cache: yes
|
||||
update_cache: true
|
||||
|
||||
- name: Install prerequisites
|
||||
ansible.builtin.apt:
|
||||
@@ -48,27 +53,30 @@
|
||||
- lsb-release
|
||||
state: present
|
||||
|
||||
- name: Create keyrings directory
|
||||
- name: Ensure /etc/apt/keyrings exists
|
||||
ansible.builtin.file:
|
||||
path: /etc/apt/keyrings
|
||||
state: directory
|
||||
mode: '0755'
|
||||
mode: "0755"
|
||||
|
||||
- name: Add Docker GPG key
|
||||
- name: Download Docker GPG key
|
||||
ansible.builtin.get_url:
|
||||
url: https://download.docker.com/linux/ubuntu/gpg
|
||||
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:
|
||||
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
|
||||
filename: docker
|
||||
|
||||
- name: Update apt cache after adding Docker repo
|
||||
ansible.builtin.apt:
|
||||
update_cache: yes
|
||||
update_cache: true
|
||||
|
||||
- name: Install Docker engine and plugins
|
||||
ansible.builtin.apt:
|
||||
@@ -80,9 +88,31 @@
|
||||
- docker-compose-plugin
|
||||
state: present
|
||||
|
||||
- name: Start and enable Docker service
|
||||
- name: Enable and start Docker
|
||||
ansible.builtin.systemd:
|
||||
name: docker
|
||||
enabled: true
|
||||
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 }}"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user