Update proxmox-docker-install.yml
This commit is contained in:
@@ -1,118 +1,62 @@
|
|||||||
---
|
---
|
||||||
# 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:
|
ansible.builtin.get_url:
|
||||||
name:
|
url: https://download.docker.com/linux/ubuntu/gpg
|
||||||
- ca-certificates
|
dest: /etc/apt/keyrings/docker.gpg
|
||||||
- curl
|
mode: "0644"
|
||||||
- gnupg
|
|
||||||
- lsb-release
|
|
||||||
state: present
|
|
||||||
|
|
||||||
- name: Ensure /etc/apt/keyrings exists
|
- name: Add Docker apt repository
|
||||||
ansible.builtin.file:
|
ansible.builtin.apt_repository:
|
||||||
path: /etc/apt/keyrings
|
repo: >-
|
||||||
state: directory
|
deb [arch={{ deb_arch.stdout }} signed-by=/etc/apt/keyrings/docker.gpg]
|
||||||
mode: "0755"
|
https://download.docker.com/linux/ubuntu
|
||||||
|
{{ ansible_distribution_release }} stable
|
||||||
|
state: present
|
||||||
|
filename: docker
|
||||||
|
|
||||||
- name: Download Docker GPG key
|
- name: Update apt cache after Docker repo
|
||||||
ansible.builtin.get_url:
|
ansible.builtin.apt:
|
||||||
url: https://download.docker.com/linux/ubuntu/gpg
|
update_cache: yes
|
||||||
dest: /etc/apt/keyrings/docker.asc
|
|
||||||
mode: "0644"
|
|
||||||
|
|
||||||
- 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
|
|
||||||
state: present
|
|
||||||
filename: docker
|
|
||||||
|
|
||||||
- name: Update apt cache after adding Docker repo
|
|
||||||
ansible.builtin.apt:
|
|
||||||
update_cache: true
|
|
||||||
|
|
||||||
- name: Install Docker engine and plugins
|
|
||||||
ansible.builtin.apt:
|
|
||||||
name:
|
|
||||||
- docker-ce
|
|
||||||
- docker-ce-cli
|
|
||||||
- containerd.io
|
|
||||||
- docker-buildx-plugin
|
|
||||||
- docker-compose-plugin
|
|
||||||
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 }}"
|
|
||||||
|
|
||||||
|
- name: Install Docker engine and plugins
|
||||||
|
ansible.builtin.apt:
|
||||||
|
name:
|
||||||
|
- docker-ce
|
||||||
|
- docker-ce-cli
|
||||||
|
- containerd.io
|
||||||
|
- docker-buildx-plugin
|
||||||
|
- docker-compose-plugin
|
||||||
|
state: present
|
||||||
|
|||||||
Reference in New Issue
Block a user