# SPDX-License-Identifier: MIT
---
- name: Test bootloader_settings variable
  hosts: all
  gather_facts: false
  tasks:
    - name: Run in a block to clean up afterwards
      block:
        - name: Skip on s390x architecture
          include_tasks: tasks/skip_on_s390x.yml

        - name: Set boot loader password
          vars:
            bootloader_password: test-pass
          include_role:
            name: fedora.linux_system_roles.bootloader

        - name: Get contents of {{ __bootloader_user_conf }}
          command: cat {{ __bootloader_user_conf }}
          failed_when: >-
            not (__bootloader_user_conf_content.stdout |
            regex_search('^GRUB2_PASSWORD=grub\.pbkdf2\.sha512\.10000\..*'))
          register: __bootloader_user_conf_content
          changed_when: false

        - name: Remove boot loader password
          vars:
            bootloader_remove_password: true
          include_role:
            name: fedora.linux_system_roles.bootloader

        - name: Get stat of {{ __bootloader_user_conf }}
          stat:
            path: "{{ __bootloader_user_conf }}"
          register: __bootloader_user_conf_stat

        - name: Verify that user conf doesn't exist
          assert:
            that: not __bootloader_user_conf_stat.stat.exists
      always:
        - name: Remove boot loader password
          vars:
            bootloader_remove_password: true
          include_role:
            name: fedora.linux_system_roles.bootloader
