Skip to content

Commit a733527

Browse files
committed
Kayobe multiple environments support
Adds a mandatory parameter - kayobe environment name, allowing for separate configs per env in the same branch.
1 parent 8cf03a8 commit a733527

1 file changed

Lines changed: 17 additions & 9 deletions

File tree

tools/openstack-config

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,38 @@ SCRIPT=${BASH_SOURCE[0]}
44
TOOLS_PATH=$(dirname ${SCRIPT})
55
OPENSTACK_CONFIG_PATH=$(dirname ${TOOLS_PATH})
66
cd ${OPENSTACK_CONFIG_PATH}
7+
MANDATORY_PARAM=false
78

89
PLAYBOOK=ansible/openstack.yml
910

10-
while getopts ":p:" opt; do
11+
while getopts ":p:e:" opt; do
1112
case $opt in
1213
p)
1314
PLAYBOOK=${OPTARG}
1415
;;
16+
17+
e)
18+
MANDATORY_PARAM=true;
19+
ENV="-${OPTARG}"
20+
;;
1521
\?)
16-
echo "Invalid option: -$opt"
17-
echo "Usage: ${0} [-p <playbook>] [-- <other arguments to ansible-playbook>]"
22+
echo "Invalid option: -$OPTARG"
23+
echo "Usage: ${0} [-p <playbook>] [-e <kayobe environment name>] [-- <other arguments to ansible-playbook>]"
1824
exit 1
1925
;;
2026
esac
21-
if [[ -n ${OPTARG} ]]; then
22-
shift
23-
fi
24-
shift
2527
done
2628

27-
if [[ $1 == '--' ]]; then
28-
shift
29+
# Fail as mandatory environment paremeter is missing
30+
if ! $MANDATORY_PARAM
31+
then
32+
echo "-e missing - environment parameter is mandatory" >&2
33+
exit 1
2934
fi
3035

36+
# Removing parameters already parsed with getopts
37+
shift $(( OPTIND - 1 ))
38+
3139
echo "Running playbook $PLAYBOOK"
3240

3341
exec ansible-playbook \

0 commit comments

Comments
 (0)