File tree 1 file changed +45
-0
lines changed
1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change
1
+ #! /usr/bin/env bash
2
+ # vim:ts=4:sts=4:sw=4:et
3
+ #
4
+ # Author: Hari Sekhon
5
+ # Date: 2024-02-28 12:40:41 +0000 (Wed, 28 Feb 2024)
6
+ #
7
+ # https///github.com/HariSekhon/DevOps-Bash-tools
8
+ #
9
+ # License: see accompanying Hari Sekhon LICENSE file
10
+ #
11
+ # If you're using my code you're welcome to connect with me on LinkedIn and optionally send me feedback to help steer this or other code I publish
12
+ #
13
+ # https://www.linkedin.com/in/HariSekhon
14
+ #
15
+
16
+ set -euo pipefail
17
+ [ -n " ${DEBUG:- } " ] && set -x
18
+ srcdir=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd) "
19
+
20
+ # shellcheck disable=SC1090,SC1091
21
+ . " $srcdir /lib/utils.sh"
22
+
23
+ # shellcheck disable=SC2034,SC2154
24
+ usage_description="
25
+ SSH keyscans all the GCE VM hosts that match the given regex filter to add them to SSH known_hosts
26
+
27
+ Useful to doing direct SSH to hosts and especially for Ansible to speed up not going through IAP which is slow
28
+ and not having them prompt to accept the SSH keys
29
+ "
30
+
31
+ # used by usage() in lib/utils.sh
32
+ # shellcheck disable=SC2034
33
+ usage_args=" [<regex_filter> <gcloud_cli_options>]"
34
+
35
+ help_usage " $@ "
36
+
37
+ # max_args 1 "$@"
38
+
39
+ ssh_known_hosts_file=~ /.ssh/known_hosts
40
+
41
+ " $srcdir /gce_host_ips.sh" " $@ " |
42
+ while read -r ip hostname; do
43
+ ssh-keyscan " $ip " >> " $ssh_known_hosts_file "
44
+ ssh-keyscan " $hostname " >> " $ssh_known_hosts_file "
45
+ done
You can’t perform that action at this time.
0 commit comments