forked from wunderio/WunderTools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprovision.sh
executable file
·65 lines (56 loc) · 1.7 KB
/
provision.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
#!/bin/bash
VAULT_FILE=$WT_ANSIBLE_VAULT_FILE
FIRST_RUN=0
MYSQL_ROOT_PASS=
show_help() {
cat <<EOF
Usage: ${0##*/} [-fm MYSQL_ROOT_PASS] [-v ANSIBLE_VAULT_FILE] [ENVIRONMENT]
-f First run, use when provisioning new servers.
-m MYSQL_ROOT_PASS For first run you need to provide new mysql root password.
-v ANSIBLE_VAULT_FILE Path to ansible vault password. This can also be provided with WT_ANSIBLE_VAULT_FILE environment variable.
ENVIRONMENT Environment to be provisioned.
EOF
}
OPTIND=1
while getopts "hfvm:" opt; do
case "$opt" in
h)
show_help
exit 0
;;
v) VAULT_FILE=$OPTARG
;;
f) FIRST_RUN=1
;;
m) MYSQL_ROOT_PASS=$OPTARG
;;
esac
done
shift "$((OPTIND-1))"
ENVIRONMENT=$1
if [ -z $ENVIRONMENT ]; then
show_help
exit 1
fi
if [ -z $VAULT_FILE ]; then
echo "Vault password file missing."
echo "You can provide the path to the file with -v option."
echo "Alternatively you can set WT_ANSIBLE_VAULT_FILE environment variable."
exit 1
fi
pushd `dirname $0` > /dev/null
ROOT=`pwd -P`
popd > /dev/null
PLAYBOOKPATH=$ROOT/conf/$ENVIRONMENT.yml
INVENTORY=$ROOT/conf/server.inventory
EXTRA_VARS=$ROOT/conf/variables.yml
if [ $FIRST_RUN ]; then
if [ -z $MYSQL_ROOT_PASS ]; then
echo "Mysql root password missing. You need to provide password using -m flag."
exit 1
else
ansible-playbook -C $PLAYBOOKPATH -c ssh -i $INVENTORY -e "@$EXTRA_VARS" -e "change_db_root_password=True mariadb_root_password=$MYSQL_ROOT_PASS" --ask-pass --vault-password-file=$VAULT_FILE
fi
else
ansible-playbook -C $PLAYBOOKPATH -c ssh -i $INVENTORY -e $EXTRA_VARS --vault-password-file=$VAULT_FILE
fi