---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later

- name: Create (check)
  luks_device:
    device: "{{ cryptfile_device }}"
    state: present
    keyfile: "{{ remote_tmp_dir }}/keyfile1"
    pbkdf:
      iteration_time: 0.1
  check_mode: true
  become: true
  register: create_check
- name: Create
  luks_device:
    device: "{{ cryptfile_device }}"
    state: present
    keyfile: "{{ remote_tmp_dir }}/keyfile1"
    pbkdf:
      iteration_time: 0.1
  become: true
  register: create
- name: Create (idempotent)
  luks_device:
    device: "{{ cryptfile_device }}"
    state: present
    keyfile: "{{ remote_tmp_dir }}/keyfile1"
    pbkdf:
      iteration_time: 0.1
  become: true
  register: create_idem
- name: Create (idempotent, check)
  luks_device:
    device: "{{ cryptfile_device }}"
    state: present
    keyfile: "{{ remote_tmp_dir }}/keyfile1"
    pbkdf:
      iteration_time: 0.1
  check_mode: true
  become: true
  register: create_idem_check
- assert:
    that:
    - create_check is changed
    - create is changed
    - create_idem is not changed
    - create_idem_check is not changed

- name: Open (check)
  luks_device:
    device: "{{ cryptfile_device }}"
    state: opened
    keyfile: "{{ remote_tmp_dir }}/keyfile1"
  check_mode: true
  become: true
  register: open_check
- name: Open
  luks_device:
    device: "{{ cryptfile_device }}"
    state: opened
    keyfile: "{{ remote_tmp_dir }}/keyfile1"
  become: true
  register: open
- name: Open (idempotent)
  luks_device:
    device: "{{ cryptfile_device }}"
    state: opened
    keyfile: "{{ remote_tmp_dir }}/keyfile1"
  become: true
  register: open_idem
- name: Open (idempotent, check)
  luks_device:
    device: "{{ cryptfile_device }}"
    state: opened
    keyfile: "{{ remote_tmp_dir }}/keyfile1"
  check_mode: true
  become: true
  register: open_idem_check
- assert:
    that:
    - open_check is changed
    - open is changed
    - open_idem is not changed
    - open_idem_check is not changed

- name: Closed (via name, check)
  luks_device:
    name: "{{ open.name }}"
    state: closed
  check_mode: true
  become: true
  register: close_check
- name: Closed (via name)
  luks_device:
    name: "{{ open.name }}"
    state: closed
  become: true
  register: close
- name: Closed (via name, idempotent)
  luks_device:
    name: "{{ open.name }}"
    state: closed
  become: true
  register: close_idem
- name: Closed (via name, idempotent, check)
  luks_device:
    name: "{{ open.name }}"
    state: closed
  check_mode: true
  become: true
  register: close_idem_check
- assert:
    that:
    - close_check is changed
    - close is changed
    - close_idem is not changed
    - close_idem_check is not changed

- name: Re-open
  luks_device:
    device: "{{ cryptfile_device }}"
    state: opened
    keyfile: "{{ remote_tmp_dir }}/keyfile1"
  become: true

- name: Closed (via device, check)
  luks_device:
    device: "{{ cryptfile_device }}"
    state: closed
  check_mode: true
  become: true
  register: close_check
- name: Closed (via device)
  luks_device:
    device: "{{ cryptfile_device }}"
    state: closed
  become: true
  register: close
- name: Closed (via device, idempotent)
  luks_device:
    device: "{{ cryptfile_device }}"
    state: closed
  become: true
  register: close_idem
- name: Closed (via device, idempotent, check)
  luks_device:
    device: "{{ cryptfile_device }}"
    state: closed
  check_mode: true
  become: true
  register: close_idem_check
- assert:
    that:
    - close_check is changed
    - close is changed
    - close_idem is not changed
    - close_idem_check is not changed

- name: Re-opened
  luks_device:
    device: "{{ cryptfile_device }}"
    state: opened
    keyfile: "{{ remote_tmp_dir }}/keyfile1"
  become: true

- name: Absent (check)
  luks_device:
    device: "{{ cryptfile_device }}"
    state: absent
  check_mode: true
  become: true
  register: absent_check
- name: Absent
  luks_device:
    device: "{{ cryptfile_device }}"
    state: absent
  become: true
  register: absent
- name: Absent (idempotence)
  luks_device:
    device: "{{ cryptfile_device }}"
    state: absent
  become: true
  register: absent_idem
- name: Absent (idempotence, check)
  luks_device:
    device: "{{ cryptfile_device }}"
    state: absent
  check_mode: true
  become: true
  register: absent_idem_check
- assert:
    that:
    - absent_check is changed
    - absent is changed
    - absent_idem is not changed
    - absent_idem_check is not changed
