# SPDX-License-Identifier: MIT
---
- name: Configure pcsd permissions
  hosts: all
  vars_files: vars/main.yml
  vars:
    ha_cluster_cluster_present: true
    ha_cluster_pcs_permission_list:
      - type: group
        name: haclient
        allow_list:
          - grant
          - read
          - write
      - type: user
        name: full_access
        allow_list:
          - full
      - type: group
        name: operator
        allow_list:
          - read
          - write
    ha_cluster_export_configuration: true

  tasks:
    - name: Run test
      tags: tests::verify
      block:
        - name: Set up test environment
          include_role:
            name: linux-system-roles.ha_cluster
            tasks_from: test_setup.yml

        - name: Run HA Cluster role
          include_role:
            name: linux-system-roles.ha_cluster
            public: true

        - name: Check exported configuration
          vars:
            __test_exported_config: >
              {{
                ha_cluster_facts | combine({
                  'ha_cluster_enable_repos': 'it depends on test environment',
                  'ha_cluster_enable_repos_resilient_storage': 'it depends on test environment',
                  'ha_cluster_manage_firewall': 'it depends on test environment',
                  'ha_cluster_manage_selinux': 'it depends on test environment',
                  'ha_cluster_install_cloud_agents': 'it depends on test environment',
                  'ha_cluster_node_options': 'it depends on test environment'
                })
              }}
            __test_expected_config:
              ha_cluster_cluster_present: true
              ha_cluster_cluster_name: my-cluster
              ha_cluster_start_on_boot: true
              ha_cluster_transport:
                type: knet
                crypto:
                  - name: cipher
                    value: aes256
                  - name: hash
                    value: sha256
              ha_cluster_pcs_permission_list: "{{ ha_cluster_pcs_permission_list }}"
              ha_cluster_enable_repos: "it depends on test environment"
              ha_cluster_enable_repos_resilient_storage: "it depends on test environment"
              ha_cluster_manage_firewall: "it depends on test environment"
              ha_cluster_manage_selinux: "it depends on test environment"
              ha_cluster_install_cloud_agents: "it depends on test environment"
              ha_cluster_node_options: "it depends on test environment"
          block:
            - name: Print exported configuration
              debug:
                var: __test_exported_config

            - name: Print expected configuration
              debug:
                var: __test_expected_config

            - name: Compare expected and exported configuration
              assert:
                that:
                  - __test_exported_config == __test_expected_config
