From 71261e401777d252cdde715741852b66f54397e9 Mon Sep 17 00:00:00 2001 From: Alex Tavarez Date: Tue, 14 Jul 2026 15:04:45 -0400 Subject: [PATCH] added option to script subcommand for specifying a fully qualified domain name --- skato-ansible.sh | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/skato-ansible.sh b/skato-ansible.sh index e143466..5d24e1e 100755 --- a/skato-ansible.sh +++ b/skato-ansible.sh @@ -82,7 +82,7 @@ if [[ "$1" == "init" ]]; then exit 1 fi - while getopts "htm:s:n:v:u:" opt; do + while getopts "htd:m:s:n:v:u:" opt; do case $opt in h) Help "init";; s) SKANSIBLE_STAGE="$OPTARG";; @@ -91,6 +91,7 @@ if [[ "$1" == "init" ]]; then t) SKANSIBLE_UNITTEST=True;; u) export ANSIBLE_REMOTE_USER="$OPTARG";; m) SKANSIBLE_MODE="$OPTARG";; + d) SKANSIBLE_FQDN="$OPTARG";; *) echo "Err: Invalid option set"; exit 1;; esac done @@ -99,23 +100,23 @@ if [[ "$1" == "init" ]]; then # SKANSIBLE_CONN_HOST=staging${SKANSIBLE_STAGE}.test if [[ "$SKANSIBLE_STAGE" == 0 ]]; then if [[ "$SKANSIBLE_UNITTEST" == "True" ]]; then - sudo ansible-playbook -CKk -i hosts.yml --extra-vars "chosen_host=${SKANSIBLE_CONN_HOST}" --extra-vars "chosen_user=${ANSIBLE_REMOTE_USER:-root}" --extra-vars "mode=${SKANSIBLE_MODE}" "init@${SKANSIBLE_PLAY_HOST}.yml" + sudo ansible-playbook -CKk -i hosts.yml --extra-vars "chosen_host=${SKANSIBLE_CONN_HOST}" --extra-vars "chosen_user=${ANSIBLE_REMOTE_USER:-root}" --extra-vars "mode=${SKANSIBLE_MODE}" --extra-vars "fqdn=${SKANSIBLE_FQDN:-staging.test}" "init@${SKANSIBLE_PLAY_HOST}.yml" else - sudo ansible-playbook -Kk -i hosts.yml --extra-vars "chosen_host=${SKANSIBLE_CONN_HOST}" --extra-vars "chosen_user=${ANSIBLE_REMOTE_USER:-root}" --extra-vars "mode=${SKANSIBLE_MODE}" "init@${SKANSIBLE_PLAY_HOST}.yml" + sudo ansible-playbook -Kk -i hosts.yml --extra-vars "chosen_host=${SKANSIBLE_CONN_HOST}" --extra-vars "chosen_user=${ANSIBLE_REMOTE_USER:-root}" --extra-vars "mode=${SKANSIBLE_MODE}" --extra-vars "fqdn=${SKANSIBLE_FQDN:-staging.test}" "init@${SKANSIBLE_PLAY_HOST}.yml" fi elif [[ "$SKANSIBLE_STAGE" == 1 ]]; then if [[ "$SKANSIBLE_UNITTEST" == "True" ]]; then - sudo ansible-playbook -CK -i hosts.yml --extra-vars "chosen_host=${SKANSIBLE_CONN_HOST}" --extra-vars "chosen_user=${ANSIBLE_REMOTE_USER:-root}" --extra-vars "mode=${SKANSIBLE_MODE}" "init@${SKANSIBLE_PLAY_HOST}.yml" + sudo ansible-playbook -CK -i hosts.yml --extra-vars "chosen_host=${SKANSIBLE_CONN_HOST}" --extra-vars "chosen_user=${ANSIBLE_REMOTE_USER:-root}" --extra-vars "mode=${SKANSIBLE_MODE}" --extra-vars "fqdn=${SKANSIBLE_FQDN:-staging.test}" "init@${SKANSIBLE_PLAY_HOST}.yml" else - sudo ansible-playbook -K -i hosts.yml --extra-vars "chosen_host=${SKANSIBLE_CONN_HOST}" --extra-vars "chosen_user=${ANSIBLE_REMOTE_USER:-root}" --extra-vars "mode=${SKANSIBLE_MODE}" "init@${SKANSIBLE_PLAY_HOST}.yml" + sudo ansible-playbook -K -i hosts.yml --extra-vars "chosen_host=${SKANSIBLE_CONN_HOST}" --extra-vars "chosen_user=${ANSIBLE_REMOTE_USER:-root}" --extra-vars "mode=${SKANSIBLE_MODE}" --extra-vars "fqdn=${SKANSIBLE_FQDN:-staging.test}" "init@${SKANSIBLE_PLAY_HOST}.yml" fi fi else - if [[ -z "$SKANSIBLE_CONN_HOST" ]]; then - echo "When not doing staging, chosen or preferred host must be made explicit" + if [[ -z "$SKANSIBLE_CONN_HOST" ]] && [[ -z "$SKANSIBLE_FQDN" ]]; then + echo "When not doing staging, chosen or preferred host must be made explicit as well as desired FQDN" exit 1 else - sudo ansible-playbook -Kk -i hosts.yml --extra-vars "chosen_host=${SKANSIBLE_CONN_HOST}" --extra-vars "chosen_user=${ANSIBLE_REMOTE_USER:-root}" --extra-vars "mode=prod" "init@${SKANSIBLE_PLAY_HOST}.yml" + sudo ansible-playbook -Kk -i hosts.yml --extra-vars "chosen_host=${SKANSIBLE_CONN_HOST}" --extra-vars "chosen_user=${ANSIBLE_REMOTE_USER:-root}" --extra-vars "mode=prod" --extra-vars "fqdn=${SKANSIBLE_FQDN}" "init@${SKANSIBLE_PLAY_HOST}.yml" fi fi @@ -138,7 +139,7 @@ if [[ "$1" == "bootstrap" ]]; then exit 1 fi - while getopts "htm:s:n:v:u:" opt; do + while getopts "htd:m:s:n:v:u:" opt; do case $opt in h) Help "bootstrap";; s) SKANSIBLE_STAGE="$OPTARG";; @@ -147,6 +148,7 @@ if [[ "$1" == "bootstrap" ]]; then t) SKANSIBLE_UNITTEST=True;; u) export ANSIBLE_REMOTE_USER="$OPTARG";; m) SKANSIBLE_MODE="$OPTARG";; + d) SKANSIBLE_FQDN="$OPTARG";; *) echo "Err: Invalid option set"; exit 1;; esac done @@ -155,23 +157,23 @@ if [[ "$1" == "bootstrap" ]]; then # SKANSIBLE_CONN_HOST=staging${SKANSIBLE_STAGE}.test if [[ "$SKANSIBLE_STAGE" == 0 ]]; then if [[ "$SKANSIBLE_UNITTEST" == "True" ]]; then - ansible-playbook -CKk -i hosts.yml --extra-vars "chosen_host=${SKANSIBLE_CONN_HOST}" --extra-vars "chosen_user=${ANSIBLE_REMOTE_USER:-senpai}" --extra-vars "mode=${SKANSIBLE_MODE}" "administrate@${SKANSIBLE_PLAY_HOST}.yml" + ansible-playbook -CKk -i hosts.yml --extra-vars "chosen_host=${SKANSIBLE_CONN_HOST}" --extra-vars "chosen_user=${ANSIBLE_REMOTE_USER:-senpai}" --extra-vars "mode=${SKANSIBLE_MODE}" --extra-vars "fqdn=${SKANSIBLE_FQDN:-staging.test}" "administrate@${SKANSIBLE_PLAY_HOST}.yml" else - ansible-playbook -Kk -i hosts.yml --extra-vars "chosen_host=${SKANSIBLE_CONN_HOST}" --extra-vars "chosen_user=${ANSIBLE_REMOTE_USER:-senpai}" --extra-vars "mode=${SKANSIBLE_MODE}" "administrate@${SKANSIBLE_PLAY_HOST}.yml" + ansible-playbook -Kk -i hosts.yml --extra-vars "chosen_host=${SKANSIBLE_CONN_HOST}" --extra-vars "chosen_user=${ANSIBLE_REMOTE_USER:-senpai}" --extra-vars "mode=${SKANSIBLE_MODE}" --extra-vars "fqdn=${SKANSIBLE_FQDN:-staging.test}" "administrate@${SKANSIBLE_PLAY_HOST}.yml" fi elif [[ "$SKANSIBLE_STAGE" == 1 ]]; then if [[ "$SKANSIBLE_UNITTEST" == "True" ]]; then - ansible-playbook -CK -i hosts.yml --extra-vars "chosen_host=${SKANSIBLE_CONN_HOST}" --extra-vars "chosen_user=${ANSIBLE_REMOTE_USER:-senpai}" --extra-vars "mode=${SKANSIBLE_MODE}" "administrate@${SKANSIBLE_PLAY_HOST}.yml" + ansible-playbook -CK -i hosts.yml --extra-vars "chosen_host=${SKANSIBLE_CONN_HOST}" --extra-vars "chosen_user=${ANSIBLE_REMOTE_USER:-senpai}" --extra-vars "mode=${SKANSIBLE_MODE}" --extra-vars "fqdn=${SKANSIBLE_FQDN:-staging.test}" "administrate@${SKANSIBLE_PLAY_HOST}.yml" else - ansible-playbook -K -i hosts.yml --extra-vars "chosen_host=${SKANSIBLE_CONN_HOST}" --extra-vars "chosen_user=${ANSIBLE_REMOTE_USER:-senpai}" --extra-vars "mode=${SKANSIBLE_MODE}" "administrate@${SKANSIBLE_PLAY_HOST}.yml" + ansible-playbook -K -i hosts.yml --extra-vars "chosen_host=${SKANSIBLE_CONN_HOST}" --extra-vars "chosen_user=${ANSIBLE_REMOTE_USER:-senpai}" --extra-vars "mode=${SKANSIBLE_MODE}" --extra-vars "fqdn=${SKANSIBLE_FQDN:-staging.test}" "administrate@${SKANSIBLE_PLAY_HOST}.yml" fi fi else if [[ -z "$SKANSIBLE_CONN_HOST" ]]; then - echo "When not doing staging, chosen or preferred host must be made explicit" + echo "When not doing staging, chosen or preferred host must be made explicit as well as desired FQDN" exit 1 else - ansible-playbook -Kk -i hosts.yml --extra-vars "chosen_host=${SKANSIBLE_CONN_HOST}" --extra-vars "chosen_user=${ANSIBLE_REMOTE_USER:-senpai}" --extra-vars "mode=prod" "administrate@${SKANSIBLE_PLAY_HOST}.yml" + ansible-playbook -Kk -i hosts.yml --extra-vars "chosen_host=${SKANSIBLE_CONN_HOST}" --extra-vars "chosen_user=${ANSIBLE_REMOTE_USER:-senpai}" --extra-vars "mode=prod" --extra-vars "fqdn=${SKANSIBLE_FQDN}" "administrate@${SKANSIBLE_PLAY_HOST}.yml" fi fi