Skip to content

Instantly share code, notes, and snippets.

@zealot128
Last active February 23, 2024 09:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zealot128/912e237d28e4acfed8a9c64903535905 to your computer and use it in GitHub Desktop.
Save zealot128/912e237d28e4acfed8a9c64903535905 to your computer and use it in GitHub Desktop.
Ansible: remove known hostkey from all hosts to fix mismatching host key after host recreation
# Needs jq
hosts=`ansible-inventory --list | awk -F': "' '/ansible_host/ {print $2}' | cut -d'"' -f1`
echo $hosts | xargs -I {} ssh-keygen -R {}
echo $hosts | xargs -I {} ssh-keyscan {} >> ~/.ssh/known_hosts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment