- name: create quadlet
  ansible.builtin.copy:
    dest: /etc/containers/systemd/vaultwarden.container
    content: |
      [Unit]
      After=network-online.target

      [Container]
      AutoUpdate=registry
      Image=ghcr.io/dani-garcia/vaultwarden:latest
      Exec=/start.sh
      EnvironmentFile=vaultwarden.environment
      Volume=/var/lib/vaultwarden/:/data/:idmap
      Network=host
      UserNS=auto

      [Install]
      WantedBy=default.target
  notify:
    - systemd daemon reload
    - restart quadlet
- name: create environment
  ansible.builtin.copy:
    dest: /etc/containers/systemd/vaultwarden.environment
    content: |
      DOMAIN=https://{{ public_hostname }}/vaultwarden
      SIGNUPS_DOMAINS_WHITELIST=localhost
      SIGNUPS_VERIFY=true
      SMTP_HOST=localhost
      SMTP_FROM=vaultwarden@localhost
      SMTP_SECURITY=off
      ROCKET_ADDRESS=127.0.0.1
      ROCKET_PORT=8080
  notify:
    - restart quadlet
- name: create storage
  ansible.builtin.file:
    name: /var/lib/vaultwarden
    state: directory
  notify:
    - restart quadlet
- meta: flush_handlers
- name: enable quadlet
  ansible.builtin.systemd_service:
    name: vaultwarden.service
    enabled: true
    state: started
