Guest User

Untitled

a guest
Feb 17th, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. #!/usr/bin/env bash
  2. ##
  3. ## This will update the remote ssh keys and reset the known_hosts file after a redeploy of a new VM
  4. ##
  5.  
  6.  
  7. ## will return the found *.example.com host names from an ansible file
  8. ## - alternatively, put your own logic here or give a fixed list:
  9. ## HOSTS=( host1.example.com host2.example.de )
  10. HOSTS=( $(grep -o -e "[a-zA-Z0-9\-]*\.example\.com" inventory/heidelberg/inventory) )
  11.  
  12. if [[ -z ${SSHUSER} ]]; then
  13. echo -n ssh user:
  14. read SSHUSER
  15. else
  16. echo "SSH User: ${SSHUSER}"
  17. fi
  18.  
  19.  
  20. if [[ -z ${SSHPASS} ]]; then
  21. echo -n ssh password:
  22. read -s SSHPASS
  23. echo
  24. fi
  25.  
  26. export SSHPASS="${SSHPASS}"
  27.  
  28.  
  29. if [[ -z ${SSHPASS} || -z ${SSHUSER} ]]; then
  30. echo "I require an ssh user (or \$SSHUSER) and ssh password (or \$SSHPASS)" >&2
  31. exit 1
  32. fi
  33.  
  34. for host in "${HOSTS[@]}"; do
  35. echo "Updating ${host}"
  36. ssh-keygen -R "${host}" &> /dev/null || true
  37. ssh-keyscan "${host}" >> "${HOME}/.ssh/known_hosts" 2> /dev/null
  38. sshpass -e ssh-copy-id ${SSHUSER}@${host} > /dev/null
  39. done
Add Comment
Please, Sign In to add comment