---

- name: Install pip
  apt:
    pkg:
      - python3-pip
      - apache2-utils # yes, we need htpasswd

- name: check for radicale user
  user:
    name: "radicale"
    home: "/srv/radicale"
    system: true
    state: present

- name: Installa radicale
  pip:
    name: radicale

- name: Copy settings
  template:
    src: config.j2
    dest: /srv/radicale/config
    owner: radicale
    group: radicale
    mode: 0660

- name: Copy service
  template:
    src: radicale.service.j2
    dest: /etc/systemd/system/radicale.service
    owner: radicale
    group: radicale
    mode: 0660

- name: Enable radicale
  ansible.builtin.systemd:
    name: radicale
    enabled: yes
    masked: no

- name: Make sure radicale is running
  ansible.builtin.systemd:
    state: restarted
    daemon_reload: yes
    name: radicale
