summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2020-10-03 21:40:34 +0200
committerChristian Pointner <equinox@spreadspace.org>2020-10-03 21:40:34 +0200
commit2511faa114a061a3029db0575bb69edaa66c9626 (patch)
tree6b4e79930487a6de4143e0f585c5b6535482b990
parentprepare for debian bullseye (diff)
move known-host cleanup to utils.sh
-rw-r--r--common/utils.sh28
-rwxr-xr-xinstall.sh2
-rwxr-xr-xremove-known-host.sh20
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() {
diff --git a/install.sh b/install.sh
index e91ed60b..b4056858 100755
--- a/install.sh
+++ b/install.sh
@@ -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