---
# 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 new luks
  luks_device:
    device: "{{ cryptfile_device }}"
    state: present
    keyfile: "{{ remote_tmp_dir }}/keyfile1"
    pbkdf:
      iteration_time: 0.1
  become: true
- name: Add new keyslot with same keyfile (check)
  luks_device:
    device: "{{ cryptfile_device }}"
    state: present
    new_keyslot: 1
    keyfile: "{{ remote_tmp_dir }}/keyfile1"
    new_keyfile: "{{ remote_tmp_dir }}/keyfile1"
  become: true
  ignore_errors: true
  check_mode: true
  register: keyslot_duplicate_check
- name: Add new keyslot with same keyfile
  luks_device:
    device: "{{ cryptfile_device }}"
    state: present
    new_keyslot: 1
    keyfile: "{{ remote_tmp_dir }}/keyfile1"
    new_keyfile: "{{ remote_tmp_dir }}/keyfile1"
  become: true
  ignore_errors: true
  register: keyslot_duplicate
- assert:
    that:
    - keyslot_duplicate_check is failed
    - "'Trying to add key that is already present in another slot' in keyslot_duplicate_check.msg"
    - keyslot_duplicate is failed
    - "'Trying to add key that is already present in another slot' in keyslot_duplicate.msg"
