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

- name: Ensure Quadlet files are present
  ansible.builtin.template:
    src: "{{ item }}.j2"
    dest: "/home/debian/.config/containers/systemd/{{ item }}"
    mode: '0755'
    owner: 'debian'
    group: 'debian'
  loop:
    - 'miniflux-postgres.container'

- name: Ensure Quadlet files is present
  ansible.builtin.copy:
    src: "{{ item }}"
    dest: "/home/debian/.config/containers/systemd/{{ item }}"
    mode: '0755'
    owner: 'debian'
    group: 'debian'
  loop:
    - 'miniflux-app.container'
    - 'miniflux.pod'

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

- name: Ensure environment file is present
  ansible.builtin.template:
    src: 'miniflux.env.j2'
    dest: '/etc/miniflux/miniflux.env'
    mode: '0644'
    owner: 'root'
    group: 'root'
  register: res

- name: Ensure Caddyfile is present
  copy:
    src: 'miniflux.Caddyfile'
    dest: '/etc/caddy/miniflux.Caddyfile'
    owner: root
    group: root
    mode: '0644'
  notify: reload caddy

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

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