# SPDX-License-Identifier: MIT
---
- name: Configure stonith level {{ stonith_level_index }}
  command:
    cmd: >
      pcs -f {{ __ha_cluster_tempfile_cib_xml.path | quote }}
      -- stonith level add
      {{ stonith_level.level | quote }}

      {% if stonith_level.target | d() %}
        {{ stonith_level.target | quote }}
      {% elif stonith_level.target_pattern | d() %}
        regexp%{{ stonith_level.target_pattern | quote }}
      {% else %}
        attrib%{{ stonith_level.target_attribute | quote }}={{
          stonith_level.target_value | d() | quote }}
      {% endif %}

      {% for resource_id in stonith_level.resource_ids %}
        {{ resource_id | quote }}
      {% endfor %}
  # We always need to create CIB to see whether it's the same as what is
  # already present in the cluster. However, we don't want to report it as a
  # change since the only thing which matters is pushing the resulting CIB to
  # the cluster.
  check_mode: false
  changed_when: not ansible_check_mode
