From d1d992c56f60580ec28ffcad018234163cca5dae Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Sat, 3 Oct 2020 23:03:28 +0200 Subject: remove_known_hosts: fix shell variables --- common/utils.sh | 13 +++++++------ install.sh | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/common/utils.sh b/common/utils.sh index 5199c3b6..d6795d21 100644 --- a/common/utils.sh +++ b/common/utils.sh @@ -41,13 +41,13 @@ 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} + local inventory_hostname="$1" + local ssh_hostname=$(ssh -G "$inventory_hostname" | grep "^hostname " | awk '{ print($2) }' ) + local ssh_port=$(ssh -G "$inventory_hostname" | grep "^port " | awk '{ print($2) }' ) + local known_hosts_file=$(ssh -G "$inventory_hostname" | grep "^userknownhostsfile " | awk '{ print($2) }' ) + local known_hosts_file=${known_hosts_file/#\~/$HOME} - declare -a names + local -a names names+=("$inventory_hostname") names+=("$ssh_hostname") names+=("$ssh_hostname:$ssh_port") @@ -59,6 +59,7 @@ remove_known_hosts() { names+=("$host_name") ansible_variable__get host_domain "$inventory_hostname" > /dev/null 2>&1 && names+=("$host_name.$host_domain") + local name="" for name in ${names[@]} ; do ssh-keygen -f "$known_hosts_file" -R "$name" done diff --git a/install.sh b/install.sh index b4056858..68e06553 100755 --- a/install.sh +++ b/install.sh @@ -25,7 +25,7 @@ echo "########## removing cached facts #########" rm -f ".cache/facts/$name" echo "" -echo "######## running the install playbook ########" +echo "######## running the install playbook for $name ########" declare -a extra_vars extra_vars+=(-e "install_hostname=$name") extra_vars+=(-e "install_distro=$distro") -- cgit v1.2.3