# SPDX-License-Identifier: MIT
---
- name: Pcs auth using pcs-0.10
  command:
    # Always auth all nodes to prevent possible corner cases with synchronizing
    # pcs auth tokens in the cluster when not all nodes are auth-ed.
    cmd: >
      pcs host auth -u hacluster --
      {% for node in ansible_play_hosts %}
        {{ hostvars[node].__ha_cluster_node_name | quote }}
        {% if hostvars[node].__ha_cluster_local_node.pcs_address | d("") %}
          addr={{ hostvars[node].__ha_cluster_local_node.pcs_address | quote }}
        {% endif %}
      {% endfor %}
    stdin: "{{ ha_cluster_hacluster_password }}"
  run_once: true  # noqa: run_once[task]
  changed_when: true

- name: Pcs auth for qdevice using pcs-0.10
  command:
    # Always auth all nodes to prevent possible corner cases with synchronizing
    # pcs auth tokens in the cluster when not all nodes are auth-ed.
    cmd: >
      pcs host auth -u hacluster --
      {{ __ha_cluster_qdevice_host | quote }}
      {% if __ha_cluster_qdevice_pcs_address %}
        addr={{ __ha_cluster_qdevice_pcs_address | quote }}
      {% endif %}
    stdin: "{{ ha_cluster_hacluster_qdevice_password |
      d(ha_cluster_hacluster_password) }}"
  when:
    - __ha_cluster_qdevice_model == "net"
    - __ha_cluster_qdevice_host | length > 0
    - __ha_cluster_qdevice_host not in __ha_cluster_all_node_names
  run_once: true  # noqa: run_once[task]
  changed_when: true
