---
- name: Install cryptsetup and curl
  become: true
  ansible.builtin.apt:
    name:
      - cryptsetup
      - curl
      - libc6
    state: present
  when: ansible_os_family == 'Debian'
  tags:
    - roles::encryption::packages
    - roles::encryption::volume

- name: Create folder to store volume
  become: true
  ansible.builtin.file:
    path: "{{ encryption_volumes_path }}"
    state: directory
    mode: "0750"
  tags:
    - roles::encryption::volume

- name: Copy required scripts
  become: true
  ansible.builtin.copy:
    src: "{{ item }}"
    dest: "/usr/local/bin/"
    mode: "0750"
  with_items:
    - open_volume
    - read_system_id
    - start_encryption_provider
  tags:
    - roles::encryption::volume

- name: Create encrypted volumes
  ansible.builtin.include_tasks: volume.yml
  loop: "{{ encryption_volumes }}"
  loop_control:
    loop_var: item
  tags:
    - roles::encryption::volume

- name: Create KMS service
  ansible.builtin.include_tasks: kms.yml
  tags:
    - roles::encryption::kms
