---
- name: register is_upstream variable
  shell: |
    rpm -q openstack-tripleo-heat-templates | grep '\.el[[:digit:]]\.'
  failed_when: false
  register: is_upstream

- name: Check if overcloud deployed with pacemaker
  shell: |
    source {{ undercloud_rc }}
    openstack stack output show overcloud EnabledServices | grep 'pacemaker'
  failed_when: false
  register: pacemaker_present

- name: set deployment_with_ha fact
  set_fact:
    deployment_with_ha_upstream: "{{ is_upstream.rc == 0 and pacemaker_present.rc == 0 }}"

- name: get env files used during deploy
  shell: |
    awk '/-e\s|--environment-file\s/ {gsub(/[[:space:]]/, "", $2); print $2}' {{ overcloud_deploy_script }}
  register: initial_env_file

- name: set initial_env_file fact
  set_fact:
    initial_env_file: "{{ initial_env_file }}"

- name: fetch roles-data file referenced in initial deploy script
  shell: |
    awk '/-r\s|--roles-file\s/ {gsub(/[[:space:]]/, "", $2); print $2}' {{ overcloud_deploy_script }}
  register: roles_data_file

- name: set roles-data fact
  vars:
    roles_data: "{{ roles_data_file.stdout }}"
  set_fact:
    roles_data: "{{ (roles_data_file.stdout|length > 0) | ternary(roles_data, default_roles_data)}}"
    custom_roles_used: "{{ (roles_data_file.stdout|length > 0) | ternary(true, false)}}"

- name: assert CephOSD is enabled
  shell: |
    source {{ undercloud_rc }}
    openstack stack output show -f yaml {{ overcloud_stack_name }} EnabledServices | awk '/\s+- ceph_osd/'
  register: ceph_osd_service

- name: set ceph_osd_enabled fact
  set_fact:
    ceph_osd_enabled: "{{ (ceph_osd_service.stdout|length > 0) | ternary(true, false) }}"
