Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # rename hostname.test.com into hostname as minion id.
- # as root user on salt-master
- MID=${1?Minion ID required}
- NEW_MID=${2?New minion ID required}
- set -e
- try_ping() {
- echo -n "Pinging $1 -- "
- salt "$1" test.ping | grep -E '^\s+True$' > /dev/null 2>&1 && {
- echo Responded
- } || {
- echo No response
- return 1
- }
- }
- echo Renaming minion \"${MID}\" to \"${NEW_MID}\"
- try_ping "${MID}"
- echo Rewriting /etc/salt/minion_id
- salt "${MID}" cmd.run "echo \"${NEW_MID}\" > /etc/salt/minion_id"
- echo Restarting salt minion
- salt "${MID}" service.restart salt-minion
- PKI_FROM="/etc/salt/pki/master/minions/${MID}"
- PKI_TO="/etc/salt/pki/master/minions/${NEW_MID}"
- echo "Moving PKI files from '${PKI_FROM}' to '${PKI_TO}'"
- mv -f "${PKI_FROM}" "${PKI_TO}"
- echo Sleeping for three seconds
- sleep 3
- try_ping "${NEW_MID}" || {
- echo Trying again --
- try_ping "${NEW_MID}" || {
- echo This might take a minute, keep checking:
- echo " salt \"${NEW_MID}\" test.ping"
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement