diff --git a/puppet/services/pacemaker.yaml b/puppet/services/pacemaker.yaml index d84714fa99..b2b5cf3532 100644 --- a/puppet/services/pacemaker.yaml +++ b/puppet/services/pacemaker.yaml @@ -162,6 +162,26 @@ outputs: pacemaker_cluster: state=online check_and_fail=true async: 30 poll: 4 + - name: Move virtual IPs to another node before stopping pacemaker + when: step|int == 1 + shell: | + CLUSTER_NODE=$(crm_node -n) + echo "Retrieving all the VIPs which are hosted on this node" + VIPS_TO_MOVE=$(crm_mon --as-xml | xmllint --xpath '//resource[@resource_agent = "ocf::heartbeat:IPaddr2" and @role = "Started" and @managed = "true" and ./node[@name = "'${CLUSTER_NODE}'"]]/@id' - | sed -e 's/id=//g' -e 's/"//g') + for v in ${VIPS_TO_MOVE}; do + echo "Moving VIP $v on another node" + pcs resource move $v --wait=300 + done + echo "Removing the location constraints that were created to move the VIPs" + for v in ${VIPS_TO_MOVE}; do + echo "Removing location ban for VIP $v" + ban_id=$(cibadmin --query | xmllint --xpath 'string(//rsc_location[@rsc="'${v}'" and @node="'${CLUSTER_NODE}'" and @score="-INFINITY"]/@id)' -) + if [ -n "$ban_id" ]; then + pcs constraint remove ${ban_id} + else + echo "Could not retrieve and clear location constraint for VIP $v" 2>&1 + fi + done - name: Stop pacemaker cluster when: step|int == 1 pacemaker_cluster: state=offline