From df0ab77f564a3da5eb2153e58e9dc75137eed5a9 Mon Sep 17 00:00:00 2001 From: Sergei Petrosian <30409084+spetrosi@users.noreply.github.com> Date: Fri, 10 Jun 2022 18:10:42 +0200 Subject: [PATCH] s/ansible_play_hosts_all/ansible_play_hosts/ where applicable (#51) The ha_cluster role is sometimes included within other roles. In the scenario when a play is run against multiple hosts, and some of them fail prior to including the ha_cluster role, the ha_cluster role must continue only on the active hosts. Otherwise, the ha_cluster role tries to operate on failed nodes and fails. --- tasks/check-and-prepare-role-variables.yml | 4 ++-- tasks/cluster-setup-pcs-0.10.yml | 2 +- tasks/pcs-auth-pcs-0.10.yml | 2 +- tasks/pcs-auth.yml | 2 +- tasks/presharedkey.yml | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tasks/check-and-prepare-role-variables.yml b/tasks/check-and-prepare-role-variables.yml index aab692e6..90fa6a24 100644 --- a/tasks/check-and-prepare-role-variables.yml +++ b/tasks/check-and-prepare-role-variables.yml @@ -16,7 +16,7 @@ when: - ha_cluster_sbd_enabled - > - ansible_play_hosts_all + ansible_play_hosts | map('extract', hostvars, ['ha_cluster', 'sbd_devices']) | map('default', [], true) | map('length') | unique | length > 1 @@ -32,7 +32,7 @@ - name: Collect cluster node names set_fact: __ha_cluster_all_node_names: "{{ - ansible_play_hosts_all + ansible_play_hosts | map('extract', hostvars, '__ha_cluster_node_name') | list }}" diff --git a/tasks/cluster-setup-pcs-0.10.yml b/tasks/cluster-setup-pcs-0.10.yml index b023fa9c..078bf7b2 100644 --- a/tasks/cluster-setup-pcs-0.10.yml +++ b/tasks/cluster-setup-pcs-0.10.yml @@ -11,7 +11,7 @@ {% endif %} -- {{ ha_cluster_cluster_name | quote }} - {% for node in ansible_play_hosts_all %} + {% for node in ansible_play_hosts %} {{ hostvars[node].__ha_cluster_node_name | quote }} {% for addr in hostvars[node].ha_cluster.corosync_addresses | default([]) diff --git a/tasks/pcs-auth-pcs-0.10.yml b/tasks/pcs-auth-pcs-0.10.yml index 169159f5..06bd6eac 100644 --- a/tasks/pcs-auth-pcs-0.10.yml +++ b/tasks/pcs-auth-pcs-0.10.yml @@ -6,7 +6,7 @@ # 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_all %} + {% for node in ansible_play_hosts %} {{ hostvars[node].__ha_cluster_node_name | quote }} {% if hostvars[node].ha_cluster.pcs_address | default("") %} addr={{ hostvars[node].ha_cluster.pcs_address | quote }} diff --git a/tasks/pcs-auth.yml b/tasks/pcs-auth.yml index 81671781..b7c1bd62 100644 --- a/tasks/pcs-auth.yml +++ b/tasks/pcs-auth.yml @@ -4,7 +4,7 @@ command: cmd: > pcs status pcsd -- - {% for node in ansible_play_hosts_all %} + {% for node in ansible_play_hosts %} {{ hostvars[node].__ha_cluster_node_name | quote }} {% endfor %} register: __ha_cluster_pcs_auth_status diff --git a/tasks/presharedkey.yml b/tasks/presharedkey.yml index b3d8dcd5..75ebe352 100644 --- a/tasks/presharedkey.yml +++ b/tasks/presharedkey.yml @@ -77,7 +77,7 @@ # Following variables set the fact for all nodes delegate_facts: yes delegate_to: "{{ item }}" - with_items: "{{ ansible_play_hosts_all }}" + with_items: "{{ ansible_play_hosts }}" when: - not (preshared_key_src is string and preshared_key_src | length > 1) - not ha_cluster_regenerate_keys