--- - name: Build runtime target from survey vars hosts: localhost gather_facts: false tasks: - name: Fail early if required vars missing 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)." - name: Add the chosen VM as an in-memory inventory host (password auth) 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) }}" - name: Show what we will target ansible.builtin.debug: msg: "Targeting {{ vm_user }}@{{ vm_ip }} with password auth" - name: Install Docker on chosen VM hosts: runtime become: true gather_facts: true tasks: - name: Update apt cache ansible.builtin.apt: update_cache: yes - name: Install prerequisites ansible.builtin.apt: name: - ca-certificates - curl - gnupg - lsb-release state: present - name: Create keyrings directory ansible.builtin.file: path: /etc/apt/keyrings state: directory mode: '0755' - name: Add 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 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: 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 - name: Start and enable Docker service ansible.builtin.systemd: name: docker state: started enabled: yes