-
Notifications
You must be signed in to change notification settings - Fork 5
/
kpa.sh
executable file
·129 lines (110 loc) · 3.36 KB
/
kpa.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/bin/bash
# Copyright (C) 2023 Raoul Scarazzini <rasca@mmul.it>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
usage() {
echo "$0 --project <kpa project> --kpa-yml <kpa yaml> --verbose"
echo ""
echo " -p|--project: The name of the <kpa project> stored under the projects folder"
echo " that contains the common/settings.yml general file."
echo ""
echo " -y|--yml: The name of the KPA yaml document to be processed."
echo ""
echo " -v|--verbose: Display Ansible playbook output."
}
while [ "x$1" != "x" ]; do
case "$1" in
--verbose|-v)
ANSIBLE_VERBOSE='-v'
;;
--project|-p)
KPA_PROJECT=$2
shift
# Check settings file
if [ ! -f "/kpa/projects/${KPA_PROJECT}/common/settings.yml" ]
then
echo "A settings.yml file must exists under /kpa/projects/${KPA_PROJECT}/common/!"
echo ""
usage
exit 1
fi
;;
--yml|-y)
KPA_YML=$2
shift
# Check kpa yaml
if [ ! -f "/kpa/projects/${KPA_PROJECT}/${KPA_YML}" ]
then
echo "Unable to get /kpa/projects/${KPA_PROJECT}/${KPA_YML} file!"
echo ""
usage
exit 1
fi
;;
--help|-h|-?)
usage
exit
;;
--) shift
break
;;
-*) echo "ERROR: unknown option: $1" >&2
usage >&2
exit 2
;;
*) break
;;
esac
shift
done
if [ "x${KPA_PROJECT}" == "x" ]
then
echo "Error: you need to declare the KPA project name with the -p|--project option!"
echo ""
usage
exit 1
fi
if [ "x${KPA_YML}" == "x" ]
then
echo "Error: you need to declare the KPA document yaml file with the -y|--yml option!"
echo ""
usage
exit 1
fi
# If the output dir doesn't contain the projects link, create it
if [ ! -L /kpa/output/projects ]
then
cd /kpa/output && ln -sf ../projects && cd ..
DELETE_PROJECT_SYMLINK=true
fi
echo -n "Rendering ${KPA_PROJECT} KPA project for ${KPA_YML} file -> "
# Launch ansible playbook
export ANSIBLE_INVENTORY_UNPARSED_WARNING=False
export ANSIBLE_LOCALHOST_WARNING=False
ANSIBLE_COMMAND="ansible-playbook ${ANSIBLE_VERBOSE}
-e @/kpa/projects/${KPA_PROJECT}/common/settings.yml
-e @/kpa/projects/${KPA_PROJECT}/${KPA_YML}
/kpa/playbooks/kpa_generator.yml"
[ "x${ANSIBLE_VERBOSE}" == "x" ] && ${ANSIBLE_COMMAND} &> /dev/null || ${ANSIBLE_COMMAND}
if [ $? -ne 0 ]
then
echo "Errors!"
EXIT_STATUS=1
else
echo "Completed."
EXIT_STATUS=0
fi
# Remove symlink
[ "x$DELETE_PROJECT_SYMLINK" != "x" ] && rm -f /kpa/output/projects
exit $EXIT_STATUS