-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildsite.sh
executable file
·45 lines (37 loc) · 1.09 KB
/
buildsite.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
#!/bin/sh
export TF_VAR_domain=$1
export TF_VAR_region=$2
test -z "$2" && {
echo Usage: $0 domain zone '[number of gateways] [number of docker servers]'
exit 2
}
REGIONEXISTS=`dig +short ns $TF_VAR_region.$TF_VAR_domain | wc -l`
test $REGIONEXISTS -gt 0 && {
export TF_VAR_createdomain=0
} || {
export TF_VAR_createdomain=1
}
echo 'locahost ansible_connection=local' > ansible/inventory
(cd ansible ; ansible-playbook localhost.yml -i inventory)
for DIR in gateway dockerserver ; do
export TF_VAR_instances=$3
test 0$TF_VAR_instances -lt 2 && export TF_VAR_instances=2
test -f $DIR/main.tf && {
( cd $DIR
rm -f terraform.tfstate*
terraform init
terraform plan
terraform apply
)
echo '['$DIR']' >> ansible/inventory
echo ${DIR}'['0:`expr $TF_VAR_instances - 1`']'.$TF_VAR_region.$TF_VAR_domain >> ansible/inventory
echo >> ansible/inventory
export TF_VAR_createdomain=0
}
shift
done
sleep 30
for HOST in `ansible all -i ansible/inventory --list | grep "$TF_VAR_region.$TF_VAR_domain"`
do
ssh-keyscan $HOST >> $HOME/.ssh/known_hosts
done