# SPDX-License-Identifier: MIT
---
- name: Fetch corosync configuration from the cluster
  # Remove the contents of 'Nodes:' section as it depends on
  # testing environment
  shell:
    # Delete all empty lines. Delete all indented lines in 'nodelist' section;
    # this keeps 'nodelist {\n}\n' in place. Since empty lines in between
    # 'node' section are also removed, number of nodes in the cluster doesn't
    # matter.
    cmd: |
      set -euo pipefail
      pcs cluster corosync | sed -e '/^nodelist {$/,/^}$/ { /^\s/d } ; /^$/d'
  register: __test_pcs_corosync_config
  changed_when: false

- name: Print real corosync configuration
  debug:
    var: __test_pcs_corosync_config.stdout_lines

- name: Print expected corosync configuration
  debug:
    var: __test_expected_lines | select | list

- name: Check corosync configuration
  assert:
    that:
      - __test_pcs_corosync_config.stdout_lines
        == __test_expected_lines | select | list
