---
- name: Ensure docker-compose is installed
  ansible.builtin.package:
    name: docker-compose
    state: present

- name: Ensure Docker service is running
  ansible.builtin.service:
    name: docker
    state: started
    enabled: true

- name: Setup Portainer directory
  ansible.builtin.file:
    path: /home/ubuntu/docker-compose/portainer
    state: directory
    mode: '0755'  # Optional file permissions
    owner: ubuntu  # Optional ownership
    group: ubuntu  # Optional group ownership

- name: Deploy Portainer using Docker Compose
  ansible.builtin.template:
    src: "templates/docker_compose.yaml.j2"
    dest: "/home/ubuntu/docker-compose/portainer/docker-compose.yaml"
    mode: '0755'  # Optional file permissions
    owner: ubuntu  # Optional ownership
    group: ubuntu  # Optional group ownership
  notify:
    - Start Portainer

- name: Run Portainer docker-compose up
  community.docker.docker_compose:
    project_src: /home/ubuntu/docker-compose/portainer
    state: present
