# SPDX-License-Identifier: MIT
---
- name: Ensure that the role runs with mandatory parameters populated
  hosts: all,!ad
  gather_facts: false  # test that role works in this case
  vars:
    # sample realm that will skip joining realm step
    ad_integration_realm: "{{ __ad_integration_sample_realm }}"
    ad_integration_password: Secret123

  tasks:
    - name: Set test realm
      set_fact:
        __ad_integration_sample_realm: MiXeD.cAsE

    - name: Test - Run the system role
      include_role:
        name: linux-system-roles.ad_integration

    - name: Test - Check packages are present
      block:
        - name: Gather package facts
          package_facts:
        - name: Assert that expected packages are installed
          assert:
            that:
              - "'realmd' in ansible_facts.packages"
              - "'PackageKit' in ansible_facts.packages"

    - name: Test - Check that realmd config is present
      stat:
        path: /etc/realmd.conf
      register: __stat_result
      failed_when: not __stat_result.stat.exists
      changed_when: false

    - name: Test - Check realmd headers
      include_tasks: tasks/check_header.yml
      vars:
        __file: /etc/realmd.conf
        __fingerprint: "system_role:ad_integration"

    - name: Check that realm name is all lower case
      command: >-
        grep -xF "[{{ __ad_integration_sample_realm | lower }}]"
        /etc/realmd.conf
      changed_when: false
