---
- name: Ensure data directory is present
  ansible.builtin.file:
    path: '/data/papermc/{{ item }}'
    state: directory
    mode: '0755'
    owner: 'debian'
    group: 'debian'
  loop:
    - 'cache'
    - 'worlds'
    - 'config'
    - 'backups'

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

- name: Ensure files are present
  ansible.builtin.copy:
    src: '{{ item }}'
    dest: '/etc/papermc/{{ item }}'
    mode: '0644'
    owner: 'root'
    group: 'root'
  loop:
    - 'papermc.env'
    - 'Dockerfile'
    - 'alex'

- name: Ensure user configuration directory is present
  ansible.builtin.file:
    path: '/home/debian/.config/containers/systemd'
    state: directory
    owner: 'debian'
    group: 'debian'
    mode: '0755'

- name: Ensure Container unit files are present
  ansible.builtin.copy:
    src: "papermc.container"
    dest: "/home/debian/.config/containers/systemd/papermc.container"
    mode: '0644'
    owner: 'debian'
    group: 'debian'
  register: res

- name: systemd-reload
  ansible.builtin.systemd_service:
    daemon_reload: true
    scope: "user"
  when: 'res.changed'
