PREPARE/ADDHOST: allow the ues of proxyjump with ip address

With this patch you can specify a ProxyJump for prepare-iaas-ubuntu,
prepare-iaas-debian and addhost. Example:

./prepare-iaas-debian 89.47.191.7 hj
./addhost -b -n node1.extern.drive.test.sunet.se -p hj -- 89.47.191.7

where hj is a host defined in my .ssh/config suitable for a proxyjump
to the host in question.

This makes it easier to use ip addresses for these scripts which might
be neccessary if dns takes a while to propagate.
This commit is contained in:
Micke Nordin 2023-11-29 12:10:34 +01:00
parent 1bd6524ad3
commit 71e112e009
Signed by: Micke
GPG key ID: 0DA0A7A5708FE257
3 changed files with 22 additions and 9 deletions

15
addhost
View file

@ -13,11 +13,12 @@ function usage() {
echo " <host> can be an IP number, or something that resolves to one" echo " <host> can be an IP number, or something that resolves to one"
} }
while getopts "bhn:" this; do while getopts "bhnp:" this; do
case "${this}" in case "${this}" in
h) usage; exit 0;; h) usage; exit 0;;
b) cmd_do_bootstrap="yes" ;; b) cmd_do_bootstrap="yes" ;;
n) cmd_fqdn="${OPTARG}" ; shift ;; n) cmd_fqdn="${OPTARG}" ; shift ;;
p) cmd_proxy="${OPTARG}" ; shift ;;
*) echo "Unknown option ${this}"; echo ""; usage; exit 1;; *) echo "Unknown option ${this}"; echo ""; usage; exit 1;;
esac esac
done done
@ -36,6 +37,10 @@ if test -z "$cmd_hostname"; then
exit 1 exit 1
fi fi
if [[ -n $cmd_proxy ]]; then
proxyjump="-o ProxyJump=${cmd_proxy}"
fi
test -f cosmos.conf && . ./cosmos.conf test -f cosmos.conf && . ./cosmos.conf
_remote=${remote:='ro'} _remote=${remote:='ro'}
@ -57,8 +62,8 @@ fi
if [ "$cmd_do_bootstrap" = "yes" ]; then if [ "$cmd_do_bootstrap" = "yes" ]; then
cosmos_deb=$(find apt/ -maxdepth 1 -name 'cosmos_*.deb' | sort -V | tail -1) cosmos_deb=$(find apt/ -maxdepth 1 -name 'cosmos_*.deb' | sort -V | tail -1)
scp "$cosmos_deb" apt/bootstrap-cosmos.sh root@"$cmd_hostname": scp $proxyjump "$cosmos_deb" apt/bootstrap-cosmos.sh root@"$cmd_hostname":
ssh root@"$cmd_hostname" ./bootstrap-cosmos.sh "$cmd_fqdn" "$rrepo" "$rtag" ssh root@"$cmd_hostname" $proxyjump ./bootstrap-cosmos.sh "$cmd_fqdn" "$rrepo" "$rtag"
ssh root@"$cmd_hostname" cosmos update ssh root@"$cmd_hostname" $proxyjump cosmos update
ssh root@"$cmd_hostname" cosmos apply ssh root@"$cmd_hostname" $proxyjump cosmos apply
fi fi

View file

@ -1,5 +1,6 @@
#!/bin/bash #!/bin/bash
ip="${1}" ip="${1}"
ssh_proxy="${2}"
if [[ -z "${ip}" ]]; then if [[ -z "${ip}" ]]; then
echo "Please specify a cloud image host that the script should do the following on:" echo "Please specify a cloud image host that the script should do the following on:"
@ -9,6 +10,9 @@ if [[ -z "${ip}" ]]; then
echo " #4 reboot to start using the new kernel, updated packages etc." echo " #4 reboot to start using the new kernel, updated packages etc."
exit 1 exit 1
fi fi
if [[ -n "${ssh_proxy}" ]]; then
proxyjump="-o ProxyJump=${ssh_proxy}"
fi
set -x set -x
@ -21,5 +25,5 @@ script_dir=$(dirname "$0")
# === # ===
# userdel: user debian is currently used by process 1082 # userdel: user debian is currently used by process 1082
# === # ===
ssh "debian@${ip}" "bash -s" < "$script_dir"/iaas-enable-root.sh ssh "debian@${ip}" ${proxyjump} "bash -s" < "$script_dir"/iaas-enable-root.sh
ssh "root@${ip}" "bash -s" < "$script_dir"/iaas-setup.sh ssh "root@${ip}" ${proxyjump} "bash -s" < "$script_dir"/iaas-setup.sh

View file

@ -1,5 +1,6 @@
#!/bin/bash #!/bin/bash
ip="${1}" ip="${1}"
ssh_proxy="${2}"
if [[ -z "${ip}" ]]; then if [[ -z "${ip}" ]]; then
echo "Please specify a cloud image host that the script should do the following on:" echo "Please specify a cloud image host that the script should do the following on:"
@ -10,6 +11,9 @@ if [[ -z "${ip}" ]]; then
exit 1 exit 1
fi fi
if [[ -n "${ssh_proxy}" ]]; then
proxyjump="-o ProxyJump=${ssh_proxy}"
fi
set -x set -x
# Make sure we read the additional scripts from the same directory as # Make sure we read the additional scripts from the same directory as
@ -21,5 +25,5 @@ script_dir=$(dirname "$0")
# === # ===
# userdel: user ubuntu is currently used by process 44063 # userdel: user ubuntu is currently used by process 44063
# === # ===
ssh "ubuntu@${ip}" "bash -s" < "$script_dir"/iaas-enable-root.sh ssh "ubuntu@${ip}" ${proxyjump} "bash -s" < "$script_dir"/iaas-enable-root.sh
ssh "root@${ip}" "bash -s" < "$script_dir"/iaas-setup.sh ssh "root@${ip}" ${proxyjump} "bash -s" < "$script_dir"/iaas-setup.sh