diff options
-rw-r--r-- | common/utils.sh | 28 | ||||
-rwxr-xr-x | install.sh | 2 | ||||
-rwxr-xr-x | remove-known-host.sh | 20 |
3 files changed, 30 insertions, 20 deletions
diff --git a/common/utils.sh b/common/utils.sh index d8e459a1..5199c3b6 100644 --- a/common/utils.sh +++ b/common/utils.sh @@ -38,6 +38,34 @@ ansible_variable__get() { ########################### +## remove ssh known_hosts entries + +remove_known_hosts() { + inventory_hostname="$1" + ssh_hostname=$(ssh -G "$inventory_hostname" | grep "^hostname " | awk '{ print($2) }' ) + ssh_port=$(ssh -G "$inventory_hostname" | grep "^port " | awk '{ print($2) }' ) + known_hosts_file=$(ssh -G "$inventory_hostname" | grep "^userknownhostsfile " | awk '{ print($2) }' ) + known_hosts_file=${known_hosts_file/#\~/$HOME} + + declare -a names + names+=("$inventory_hostname") + names+=("$ssh_hostname") + names+=("$ssh_hostname:$ssh_port") + names+=("[$ssh_hostname]:$ssh_port") + + ansible_variable__get ansible_host "$inventory_hostname" || exit 1 + names+=("$ansible_host") + ansible_variable__get host_name "$inventory_hostname" || exit 1 + names+=("$host_name") + ansible_variable__get host_domain "$inventory_hostname" > /dev/null 2>&1 && names+=("$host_name.$host_domain") + + for name in ${names[@]} ; do + ssh-keygen -f "$known_hosts_file" -R "$name" + done +} + + +########################### ## vault environment handling vault_environment__get() { @@ -18,7 +18,7 @@ echo "installing $name with $distro/$codename in environment '$env_group'" echo "" echo "########## clearing old ssh host keys #########" -./remove-known-host.sh "$name" +remove_known_hosts "$name" echo "" echo "########## removing cached facts #########" diff --git a/remove-known-host.sh b/remove-known-host.sh index 647909ea..9035935e 100755 --- a/remove-known-host.sh +++ b/remove-known-host.sh @@ -5,26 +5,8 @@ if [ -z "$1" ]; then exit 1 fi -short="$1" -ssh_host=$(ssh -G "$short" | grep "^hostname " | awk '{ print($2) }' ) -ssh_port=$(ssh -G "$short" | grep "^port " | awk '{ print($2) }' ) -known_hosts_file=$(ssh -G "$short" | grep "^userknownhostsfile " | awk '{ print($2) }' ) -known_hosts_file=${known_hosts_file/#\~/$HOME} - -declare -a names -names+=("$short") -names+=("$ssh_host") -names+=("$ssh_host:$ssh_port") -names+=("[$ssh_host]:$ssh_port") - cd "${BASH_SOURCE%/*}" source common/utils.sh -ansible_variable__get host_name "$short" || exit 1 -names+=("$host_name") -ansible_variable__get host_domain "$short" > /dev/null 2>&1 && names+=("$host_name.$host_domain") - -for name in ${names[@]} ; do - ssh-keygen -f "$known_hosts_file" -R "$name" -done +remove_known_hosts "$1" exit 0 |