-
Notifications
You must be signed in to change notification settings - Fork 12
/
install.sh
executable file
·77 lines (67 loc) · 1.54 KB
/
install.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
#!/bin/bash
usage() {
echo "USAGE: ${0} [-h] [-D] -H hostname [-p password_file]"
echo ""
echo "Configures the given role for the given hostname."
echo ""
echo "Options:"
echo " -h runs help (this screen)"
echo " -D debug mode on (more verbose output)"
echo ""
echo " -H the target hostname to configure"
echo " -p password_file is an optional path to a password file for Ansible"
echo ""
}
# check invocation
if (! getopts ":hDH:p:" opt); then
usage
exit $E_OPTERROR;
fi
debug_mode=0
# parse arguments
while getopts ":hDH:p:" opt; do
case $opt in
h)
usage
exit 1
;;
D)
debug_mode=1
;;
H)
hostname=($OPTARG)
;;
p)
password_file=($OPTARG)
;;
\?)
echo "Invalid option: -${OPTARG}" >&2
usage
exit 1
;;
esac
done
shift $((OPTIND -1))
virtualenv -q -p $(which python3) venv
source venv/bin/activate
# install local requirements for ansible
ansible-galaxy install -r requirements.yml
# install additional pre-requirements
pip install jmespath dnspython
# export ansible variables
export ANSIBLE_LOAD_CALLBACK_PLUGINS=1
if [ $debug_mode -eq 0 ] ; then
export ANSIBLE_STDOUT_CALLBACK="unixy"
else
export ANSIBLE_STDOUT_CALLBACK="skippy"
fi
# create hosts file
echo "[prod]" > hosts
echo "${hostname}" >> hosts
# run ansible
if [ -z $password_file ] ; then
ansible-playbook -i hosts provision.yml --vault-id @prompt
else
ansible-playbook -i hosts provision.yml --vault-password-file $password_file
fi
deactivate