---
- name: Create Vaultwarden data directories
  ansible.builtin.file:
    path: "{{ item }}"
    state: directory
    owner: root
    group: root
    mode: "0755"
  loop:
    - "{{ vaultwarden_data_dir }}"
    - "{{ vaultwarden_data_dir }}/data"
  tags: vaultwarden

- name: Deploy Docker Compose file
  ansible.builtin.template:
    src: docker-compose.yml.j2
    dest: "{{ vaultwarden_data_dir }}/docker-compose.yml"
    owner: root
    group: root
    mode: "0644"
  notify: Restart vaultwarden
  tags: vaultwarden

- name: Start Vaultwarden
  community.docker.docker_compose_v2:
    project_src: "{{ vaultwarden_data_dir }}"
    state: present
    pull: missing
  tags: vaultwarden
