Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- ##
- ## This will update the remote ssh keys and reset the known_hosts file after a redeploy of a new VM
- ##
- ## will return the found *.example.com host names from an ansible file
- ## - alternatively, put your own logic here or give a fixed list:
- ## HOSTS=( host1.example.com host2.example.de )
- HOSTS=( $(grep -o -e "[a-zA-Z0-9\-]*\.example\.com" inventory/heidelberg/inventory) )
- if [[ -z ${SSHUSER} ]]; then
- echo -n ssh user:
- read SSHUSER
- else
- echo "SSH User: ${SSHUSER}"
- fi
- if [[ -z ${SSHPASS} ]]; then
- echo -n ssh password:
- read -s SSHPASS
- echo
- fi
- export SSHPASS="${SSHPASS}"
- if [[ -z ${SSHPASS} || -z ${SSHUSER} ]]; then
- echo "I require an ssh user (or \$SSHUSER) and ssh password (or \$SSHPASS)" >&2
- exit 1
- fi
- for host in "${HOSTS[@]}"; do
- echo "Updating ${host}"
- ssh-keygen -R "${host}" &> /dev/null || true
- ssh-keyscan "${host}" >> "${HOME}/.ssh/known_hosts" 2> /dev/null
- sshpass -e ssh-copy-id ${SSHUSER}@${host} > /dev/null
- done
Add Comment
Please, Sign In to add comment