From e448cb74afcd767afe55fbd6e54bbbc2604b8f6f Mon Sep 17 00:00:00 2001 From: David Galloway Date: Tue, 28 Jun 2022 10:31:33 -0400 Subject: [PATCH] tools: Add a couple workstation scripts Signed-off-by: David Galloway --- tools/set-next-server-local.sh | 34 ++++++++++++++++++++++++++++++++++ tools/switch-secrets.sh | 17 +++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 tools/set-next-server-local.sh create mode 100644 tools/switch-secrets.sh diff --git a/tools/set-next-server-local.sh b/tools/set-next-server-local.sh new file mode 100644 index 0000000..e9834e2 --- /dev/null +++ b/tools/set-next-server-local.sh @@ -0,0 +1,34 @@ +#!/bin/bash +# Modifies dhcp config file to add or remove a next-server and filename +# The fog next-server and filename are the default for all DHCP hosts so +# entering 'cobbler' for $2 adds its next-server and filename. +# Setting 'fog' for $2 just removes it so the host entry uses the global default. +# +# This script should live on your workstation somewhere executable. +# +# It also assumes you are using tools/switch-secrets to switch between +# octo an sepia ansible inventories + +if [ $# -ne 2 ]; then + echo "Usage: $(basename $0) hostname [cobbler|fog]" + echo + echo "Example: \`$(basename $0) mira042 cobbler\` would add Cobbler's next-server and filename to mira042's DHCP entry" + echo + exit 1 +elif [ "$2" != "cobbler" ] && [ "$2" != "fog" ]; then + echo "Unrecognized option $2. Must use 'cobbler' or 'fog'" + exit 1 +else + host=$(echo $1 | cut -d '.' -f1) +fi +ls -lah /etc/ansible/hosts | grep -q octo +if [ $? -eq 0 ] +then + dhcp_server="magna001.ceph.redhat.com" +else + dhcp_server="store01.front.sepia.ceph.com" +fi + +set -x + +ssh $dhcp_server "sudo /usr/local/sbin/set-next-server.sh $host $2 && sudo service dhcpd restart" diff --git a/tools/switch-secrets.sh b/tools/switch-secrets.sh new file mode 100644 index 0000000..c0c0e54 --- /dev/null +++ b/tools/switch-secrets.sh @@ -0,0 +1,17 @@ +#!/bin/bash +# Switches your ansible inventory between ceph-sepia-secrets or ceph-octo-secrets + +val=$(ls -lah /etc/ansible/secrets | grep -c "octo") +if [ $val -eq 1 ]; then + sudo rm /etc/ansible/secrets + sudo ln -s ~/git/ceph/ceph-sepia-secrets/ansible/secrets /etc/ansible/secrets + sudo rm /etc/ansible/hosts + sudo ln -s ~/git/ceph/ceph-sepia-secrets/ansible/inventory /etc/ansible/hosts + cat ~/.teuthology.yaml.sepia > ~/.teuthology.yaml +elif [ $val -eq 0 ]; then + sudo rm /etc/ansible/secrets + sudo ln -s ~/git/ceph/ceph-octo-secrets/ansible/secrets /etc/ansible/secrets + sudo rm /etc/ansible/hosts + sudo ln -s ~/git/ceph/ceph-octo-secrets/ansible/inventory /etc/ansible/hosts + cat ~/.teuthology.yaml.octo > ~/.teuthology.yaml +fi -- 2.39.5