53 lines
1.5 KiB
Bash
Executable file
53 lines
1.5 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
#
|
|
# swap Pacemaker node IPs
|
|
#
|
|
# SPDX-License-Identifier: MIT
|
|
|
|
# Declare an empty array - do not edit
|
|
declare -a ip_pairs
|
|
|
|
## EDIT here ##
|
|
|
|
## These are basically the /etc/hosts values from old to new IP space
|
|
# add as many lines as needed; format: '<from>(comma)<to>' (no spaces!)
|
|
ip_pairs+=('172.20.21.89,172.24.16.105')
|
|
ip_pairs+=('172.20.21.90,172.24.16.107')
|
|
ip_pairs+=('172.20.20.20,172.24.16.108')
|
|
ip_pairs+=('172.20.20.21,172.24.16.109')
|
|
ip_pairs+=('10.128.132.132,10.132.143.68')
|
|
ip_pairs+=('10.128.132.133,10.132.143.69')
|
|
|
|
## STOP editing here ##
|
|
|
|
# handy for testing
|
|
cibxml=/var/lib/pacemaker/cib/cib.xml
|
|
|
|
# back everything up
|
|
echo "Backing up existing configs..."
|
|
DTS=$(date +"%Y%m%d_%H%M")
|
|
cp -a /var/lib/pacemaker/cib{,."$DTS"}
|
|
|
|
# remove the old cluster signature
|
|
echo "Removing old XML signature file..."
|
|
rm -f /var/lib/pacemaker/cib/cib.xml.sig
|
|
|
|
# for each element:
|
|
# convert comma to space to make new child array
|
|
# add escapes on . in From to prevent regex interpolation
|
|
# sed the config replace the IP
|
|
echo "Replacing IP addresses..."
|
|
# shellcheck disable=SC2068
|
|
for pair in ${ip_pairs[@]}; do
|
|
# shellcheck disable=SC2206
|
|
_tmparr=(${pair//,/ })
|
|
ipf=${_tmparr[0]//./\\.}
|
|
ipt=${_tmparr[1]}
|
|
sed -i -e "s/\b$ipf\b/$ipt/g" "${cibxml}"
|
|
done
|
|
|
|
# find the epoch (version) and increment it by +1
|
|
echo "Updating epoch (version) of config..."
|
|
epold=$(sed -n 's/.*\bepoch="\([^"]*\).*/\1/p' "${cibxml}")
|
|
epnew=$((epold+1))
|
|
sed -i -e "s/\bepoch=\"$epold\"/epoch=\"$epnew\"/g" "${cibxml}"
|