-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuilder
executable file
·84 lines (72 loc) · 1.87 KB
/
builder
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
#!/bin/bash
# Function to display help
show_help() {
echo "Usage: $0 [options] action extravars [ansible-playbook options]"
echo ""
echo "Options:"
echo " -r Use -i remote (default is -i local, ignored if action is 'prepare')"
echo " -h Display this help message"
echo ""
echo "Actions:"
echo " spawn, prepare, delete, nginx"
echo ""
echo "Example:"
echo " $0 -r spawn extravars.yml -v"
}
# Default inventory file
inventory="local"
# Parse options
while getopts ":rh" opt; do
case ${opt} in
r )
inventory="remote"
;;
h )
show_help
exit 0
;;
\? )
echo "Invalid option: -${OPTARG}" >&2
show_help
exit 1
;;
: )
echo "Option -${OPTARG} requires an argument." >&2
show_help
exit 1
;;
esac
done
shift $((OPTIND -1))
# Check if the action and user_variables are provided
if [ -z "$1" ] || [ -z "$2" ]; then
echo "Error: both action and user_variables are required."
show_help
exit 1
fi
action=$1
user_variables=$2
shift 2
# Strip .yml from the action if present
action=${action%.yml}
# Validate the action
valid_actions=("spawn" "prepare" "delete" "nginx")
if [[ ! " ${valid_actions[@]} " =~ " ${action} " ]]; then
echo "Error: invalid action. Valid actions are: spawn, prepare, delete, nginx."
show_help
exit 1
fi
vmlist=""
if [ "$action" == "prepare" ]; then
inventory="kolla-inventory"
elif [ "$action" == "delete" ]; then
vmlist="-e @vm_list.yml"
elif [ "$action" == "nginx" ]; then
inventory="remote"
fi
cmd="ansible-playbook -i $inventory $action.yml -e @$user_variables $vmlist"
# Add any remaining arguments
cmd="$cmd $@"
# Execute the ansible-playbook command
echo "Executing: $cmd"
$cmd