---
# 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 with keysize
  luks_device:
    device: "{{ cryptfile_device }}"
    state: present
    keyfile: "{{ remote_tmp_dir }}/keyfile1"
    keysize: 256
    pbkdf:
      algorithm: pbkdf2
      iteration_count: 1000
  become: true
  register: create_with_keysize
- name: Create with keysize (idempotent)
  luks_device:
    device: "{{ cryptfile_device }}"
    state: present
    keyfile: "{{ remote_tmp_dir }}/keyfile1"
    keysize: 256
    pbkdf:
      algorithm: pbkdf2
      iteration_count: 1000
  become: true
  register: create_idem_with_keysize
- name: Create with different keysize (idempotent since we do not update keysize)
  luks_device:
    device: "{{ cryptfile_device }}"
    state: present
    keyfile: "{{ remote_tmp_dir }}/keyfile1"
    keysize: 512
    pbkdf:
      algorithm: pbkdf2
      iteration_count: 1000
  become: true
  register: create_idem_with_diff_keysize
- name: Create with ambiguous arguments
  luks_device:
    device: "{{ cryptfile_device }}"
    state: present
    keyfile: "{{ remote_tmp_dir }}/keyfile1"
    passphrase: "{{ cryptfile_passphrase1 }}"
    pbkdf:
      algorithm: pbkdf2
      iteration_count: 1000
  ignore_errors: true
  become: true
  register: create_with_ambiguous

- assert:
    that:
      - create_with_keysize is changed
      - create_idem_with_keysize is not changed
      - create_idem_with_diff_keysize is not changed
      - create_with_ambiguous is failed
