---
- name: Ensure ansible_facts used by role
  setup:
    gather_subset: "{{ __ha_cluster_required_facts_subsets }}"
  when: __ha_cluster_required_facts |
    difference(ansible_facts.keys() | list) | length > 0

- name: Determine if system is ostree and set flag
  when: not __ha_cluster_is_ostree is defined
  block:
    - name: Check if system is ostree
      stat:
        path: /run/ostree-booted
      register: __ostree_booted_stat

    - name: Set flag to indicate system is ostree
      set_fact:
        __ha_cluster_is_ostree: "{{ __ostree_booted_stat.stat.exists }}"

- name: Set platform/version specific variables
  include_vars: "{{ __vars_file }}"
  loop:
    - "{{ ansible_facts['os_family'] }}.yml"
    - "{{ ansible_facts['distribution'] }}.yml"
    # Enables loading of shared vars between SLES and SLES_SAP
    - >-
      {{ ansible_facts['distribution'].split("_")[0] ~ '_' ~
      ansible_facts['distribution_major_version'] }}.yml
    - >-
      {{ ansible_facts['distribution'].split("_")[0] ~ '_' ~
      ansible_facts['distribution_version'] }}.yml

    - >-
      {{ ansible_facts['distribution'] ~ '_' ~
      ansible_facts['distribution_major_version'] }}.yml
    - >-
      {{ ansible_facts['distribution'] ~ '_' ~
      ansible_facts['distribution_version'] }}.yml
  vars:
    __vars_file: "{{ role_path }}/vars/{{ item }}"
  when: __vars_file is file

- name: Set Linux Pacemaker shell specific variables
  include_vars: "{{ role_path }}/vars/shell_{{ ha_cluster_pacemaker_shell }}.yml"  # yamllint disable-line rule:line-length
