# SPDX-License-Identifier: MIT
---
- name: Configure cluster properties - one set
  hosts: all
  vars_files: vars/main.yml
  vars:
    ha_cluster_cluster_name: test-cluster
    ha_cluster_cluster_properties:
      - attrs:
          - name: stonith-enabled
            value: 'true'
          - name: no-quorum-policy
            value: stop
    ha_cluster_manage_firewall: true
    ha_cluster_manage_selinux: 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: Fetch cluster versions of cluster components
          include_tasks: tasks/fetch_versions.yml

        - name: Fetch cluster properties configuration from the cluster
          command:
            cmd: pcs property
          register: __test_pcs_property_config
          changed_when: false

        - name: Debug cluster properties configuration
          debug:
            var: __test_pcs_property_config

        - name: Check cluster properties configuration
          assert:
            that:
              - "'no-quorum-policy: stop' in stdout_lines"
              - "'stonith-enabled: true' in stdout_lines"
          vars:
            stdout_lines: "{{
              __test_pcs_property_config.stdout_lines | map('trim') | list }}"
          when:
            - >
              not((__test_pcs_version is version('0.11', '>='))
              and
              ('pcmk.properties.cluster.config.output-formats'
              in __test_pcs_capabilities))

        - name: Check cluster properties configuration
          assert:
            that:
              - "'no-quorum-policy=stop' in stdout_lines"
              - "'stonith-enabled=true' in stdout_lines"
          vars:
            stdout_lines: "{{
              __test_pcs_property_config.stdout_lines | map('trim') | list }}"
          when:
            - >
              (__test_pcs_version is version('0.11', '>='))
              and
              ('pcmk.properties.cluster.config.output-formats'
              in __test_pcs_capabilities)

        - name: Check firewall and selinux state
          include_tasks: tasks/check_firewall_selinux.yml
