---
- name: Ensure data subvolume is present
  community.general.btrfs_subvolume:
    name: '/baikal'

- name: Ensure data directories are present
  ansible.builtin.file:
    path: '/mnt/data1/baikal/{{ item }}'
    state: directory
    mode: '0755'
    owner: 'root'
    group: 'root'
  loop:
    - 'Specific'
    - 'config'

- name: Ensure configuration directory is present
  ansible.builtin.file:
    path: '/etc/baikal'
    state: directory
    mode: '0755'

- name: Ensure compose file is present
  ansible.builtin.copy:
    src: 'compose.yml'
    dest: '/etc/baikal/compose.yml'
    mode: '0644'
    owner: 'root'
    group: 'root'
  register: res

- name: Ensure stack is deployed
  ansible.builtin.shell:
    chdir: '/etc/baikal'
    cmd: 'docker compose up -d --remove-orphans'
  when: 'res.changed'

- name: Ensure backup script is present
  ansible.builtin.copy:
    src: 'baikal.backup.sh'
    dest: '/etc/backups/baikal.backup.sh'
    owner: 'root'
    group: 'root'
    mode: '0644'
