- name: Install Docker and Compose using official script (recommended)
  hosts: hip
  become: true

  tasks:
    - name: Download and run Docker installation script
      ansible.builtin.shell: |
        curl -fsSL https://get.docker.com -o /tmp/get-docker.sh
        sh /tmp/get-docker.sh
      args:
        creates: /usr/bin/docker
      register: install_result

    - name: Show installation output
      ansible.builtin.debug:
        msg: "{{ install_result.stdout_lines }}"

    - name: Add current user to docker group
      ansible.builtin.user:
        name: "{{ ansible_user }}"
        groups: docker
        append: true
      when: ansible_user != 'root'

    - name: Verify Docker Compose V2 installation
      ansible.builtin.command: docker compose version
      register: compose_version
      changed_when: false

    - name: Show Compose version
      ansible.builtin.debug:
        msg: "Docker Compose: {{ compose_version.stdout }}"
