From a73352784754a58bcc1109f21587e0be3e2a91c1 Mon Sep 17 00:00:00 2001 From: Jakub Darmach Date: Mon, 23 Sep 2024 13:34:06 +0200 Subject: [PATCH] Kayobe multiple environments support Adds a mandatory parameter - kayobe environment name, allowing for separate configs per env in the same branch. --- tools/openstack-config | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/tools/openstack-config b/tools/openstack-config index 055a62c..d149738 100755 --- a/tools/openstack-config +++ b/tools/openstack-config @@ -4,30 +4,38 @@ SCRIPT=${BASH_SOURCE[0]} TOOLS_PATH=$(dirname ${SCRIPT}) OPENSTACK_CONFIG_PATH=$(dirname ${TOOLS_PATH}) cd ${OPENSTACK_CONFIG_PATH} +MANDATORY_PARAM=false PLAYBOOK=ansible/openstack.yml -while getopts ":p:" opt; do +while getopts ":p:e:" opt; do case $opt in p) PLAYBOOK=${OPTARG} ;; + + e) + MANDATORY_PARAM=true; + ENV="-${OPTARG}" + ;; \?) - echo "Invalid option: -$opt" - echo "Usage: ${0} [-p ] [-- ]" + echo "Invalid option: -$OPTARG" + echo "Usage: ${0} [-p ] [-e ] [-- ]" exit 1 ;; esac - if [[ -n ${OPTARG} ]]; then - shift - fi - shift done -if [[ $1 == '--' ]]; then - shift +# Fail as mandatory environment paremeter is missing +if ! $MANDATORY_PARAM +then + echo "-e missing - environment parameter is mandatory" >&2 + exit 1 fi +# Removing parameters already parsed with getopts +shift $(( OPTIND - 1 )) + echo "Running playbook $PLAYBOOK" exec ansible-playbook \