--- - 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. Supply vm_ip, vm_user, vm_pass in the Task Template Survey." - 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_become: true ansible_become_method: sudo ansible_become_password: "{{ vm_pass }}" 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" - name: Install Docker on chosen VM hosts: runtime become: true gather_facts: true tasks: - name: Update apt cache ansible.builtin.apt: update_cache: true # Universe is required for some packages on Ubuntu minimal/cloud images - name: Ensure Ubuntu repositories (universe) are enabled ansible.builtin.apt_repository: repo: "deb http://archive.ubuntu.com/ubuntu {{ ansible_distribution_release }} universe" state: present when: ansible_distribution == "Ubuntu" - name: Update apt cache after enabling universe 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 (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 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: Update apt cache after adding Docker repo ansible.builtin.apt: update_cache: true # ---- Install path A: Docker CE (preferred) ---- - name: Install Docker from Ubuntu repo (Ubuntu 24.04 noble) ansible.builtin.apt: name: - docker.io - docker-compose-v2 state: present update_cache: true - name: Enable and start Docker service 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: Compose version (v2 if available, else v1) ansible.builtin.shell: | set -e if docker compose version >/dev/null 2>&1; then docker compose version else docker-compose --version fi register: compose_version changed_when: false - name: Print versions ansible.builtin.debug: msg: - "{{ docker_version.stdout }}" - "{{ compose_version.stdout }}"