---
- name: Create dashboard data directory
  ansible.builtin.file:
    path: "{{ dashboard_data_dir }}"
    state: directory
    owner: root
    group: root
    mode: "0755"
  tags: dashboard

- name: Deploy background image
  ansible.builtin.copy:
    src: bg.jpg
    dest: "{{ dashboard_data_dir }}/bg.jpg"
    owner: root
    group: root
    mode: "0644"
  notify: Restart dashboard
  tags: dashboard

- name: Deploy dashboard app
  ansible.builtin.template:
    src: app.py.j2
    dest: "{{ dashboard_data_dir }}/app.py"
    owner: root
    group: root
    mode: "0644"
  notify: Restart dashboard
  tags: dashboard

- name: Deploy Docker Compose file
  ansible.builtin.template:
    src: docker-compose.yml.j2
    dest: "{{ dashboard_data_dir }}/docker-compose.yml"
    owner: root
    group: root
    mode: "0644"
  notify: Restart dashboard
  tags: dashboard

- name: Start dashboard
  community.docker.docker_compose_v2:
    project_src: "{{ dashboard_data_dir }}"
    state: present
    pull: missing
  tags: dashboard
