Advertisement
Guest User

Untitled

a guest
Jul 25th, 2017
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.00 KB | None | 0 0
  1. # rename hostname.test.com into hostname as minion id.
  2. # as root user on salt-master
  3. MID=${1?Minion ID required}
  4. NEW_MID=${2?New minion ID required}
  5.  
  6. set -e
  7.  
  8. try_ping() {
  9.   echo -n "Pinging $1 -- "
  10.   salt "$1" test.ping | grep -E '^\s+True$' > /dev/null 2>&1 && {
  11.     echo Responded
  12.   } || {
  13.     echo No response
  14.     return 1
  15.   }
  16. }
  17.  
  18. echo Renaming minion \"${MID}\" to \"${NEW_MID}\"
  19.  
  20. try_ping "${MID}"
  21.  
  22. echo Rewriting /etc/salt/minion_id
  23. salt "${MID}" cmd.run "echo \"${NEW_MID}\" > /etc/salt/minion_id"
  24.  
  25. echo Restarting salt minion
  26. salt "${MID}" service.restart salt-minion
  27.  
  28. PKI_FROM="/etc/salt/pki/master/minions/${MID}"
  29. PKI_TO="/etc/salt/pki/master/minions/${NEW_MID}"
  30. echo "Moving PKI files from '${PKI_FROM}' to '${PKI_TO}'"
  31. mv -f "${PKI_FROM}" "${PKI_TO}"
  32.  
  33. echo Sleeping for three seconds
  34. sleep 3
  35. try_ping "${NEW_MID}" || {
  36.   echo Trying again --
  37.   try_ping "${NEW_MID}" || {
  38.     echo This might take a minute, keep checking:
  39.     echo "  salt \"${NEW_MID}\" test.ping"
  40.   }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement