diff --git a/proxmox-docker-install.yml b/proxmox-docker-install.yml index 2393a33..42ba26b 100644 --- a/proxmox-docker-install.yml +++ b/proxmox-docker-install.yml @@ -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) hosts: localhost gather_facts: false - tasks: - name: Validate required inputs ansible.builtin.assert: that: - vm_ip is defined - - vm_user is defined - - vm_pass is defined - fail_msg: "Missing required vars. You must supply vm_ip, vm_user, vm_pass in the Task Template Survey." + fail_msg: "Missing vm_ip in Survey." - - name: Add VM as in-memory inventory host (force password SSH) + - name: Add VM as in-memory inventory host ansible.builtin.add_host: name: target_vm groups: runtime ansible_host: "{{ vm_ip }}" - ansible_user: "{{ vm_user }}" - ansible_password: "{{ vm_pass }}" - ansible_become: true - ansible_become_method: sudo - ansible_become_password: "{{ vm_pass }}" + # user/pass will come from Semaphore credentials ansible_ssh_common_args: >- -o PreferredAuthentications=password -o PubkeyAuthentication=no + -o IdentitiesOnly=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null - name: Show connection target 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: Update apt cache - ansible.builtin.apt: - update_cache: true +- name: Get system architecture + ansible.builtin.command: dpkg --print-architecture + register: deb_arch + changed_when: false - - name: Install prerequisites - ansible.builtin.apt: - name: - - ca-certificates - - curl - - gnupg - - lsb-release - state: present +- name: Download Docker GPG key + ansible.builtin.get_url: + url: https://download.docker.com/linux/ubuntu/gpg + dest: /etc/apt/keyrings/docker.gpg + mode: "0644" - - name: Ensure /etc/apt/keyrings exists - ansible.builtin.file: - path: /etc/apt/keyrings - state: directory - mode: "0755" +- name: Add Docker apt repository + ansible.builtin.apt_repository: + 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: Download Docker GPG key - ansible.builtin.get_url: - url: https://download.docker.com/linux/ubuntu/gpg - 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: Update apt cache after Docker repo + ansible.builtin.apt: + update_cache: yes +- 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