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 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'common/utils.sh') 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 -- cgit v1.2.3