-
Notifications
You must be signed in to change notification settings - Fork 2
/
factorio_deploy.sh
executable file
·51 lines (32 loc) · 1.3 KB
/
factorio_deploy.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
#!/bin/sh
set -o nounset # Treat unset variables as an error
summon_terraform(){
git_url_keys=$(grep 'git_ssh_keys' configuration.yml | awk '{ print $2 }' | tr -d '"')
cd terraform/
git_ssh_keys=$(curl --fail-early "$git_url_keys")
if [[ -z $(echo -ne "$git_ssh_keys") ]] ; then
echo -e "Please put your public ssh keys on github.com or gitlab.com"
exit 1
fi
# Link Terraform tf file base on backend now only Hetzner is support
ln -sf "backends/hetzner.tf" cloud.tf
# Init Terraform if required
[ -d ./.terraform ] || terraform init
./scripts/run_terraform_pass.sh apply
cd -
}
summon_ansible() {
machine_ip=$(cd terraform && ./scripts/terraform_ip_list.sh && cd ..)
factorio_save=$(grep 'factorio_save:' configuration.yml | awk -F'factorio_save: ' '{ print $2 }')
cp "$factorio_save" ansible/roles/factorio/files/$(basename "$factorio_save")
cd ansible/
sed -i "s/ansible_host: .*$/ansible_host: $machine_ip/g" production.yml
ansible-playbook -i production.yml site.yml
cd -
}
echo -e "[ ] Summoning Terraform"
summon_terraform
echo -e "It seems that Terraform is happy with your configuration!"
echo -e "[ ] Summoning Ansible"
summon_ansible
echo -e "It seems that Ansible is happy with your configuration!"