summaryrefslogtreecommitdiff
path: root/common
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 /common
parentprepare for debian bullseye (diff)
move known-host cleanup to utils.sh
Diffstat (limited to 'common')
-rw-r--r--common/utils.sh28
1 files changed, 28 insertions, 0 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() {