-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
69 lines (48 loc) · 1.6 KB
/
Makefile
File metadata and controls
69 lines (48 loc) · 1.6 KB
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
## Terraform
environment ?= dev
init:
cd terraform && terraform init
login:
cd terraform && terraform login
upgrade:
cd terraform && terraform init -upgrade
migrate:
cd terraform && terraform init -migrate-state
start:
cd terraform && terraform $(action) -var-file="config/$(environment).tfvars" -compact-warnings
plan:
cd terraform && terraform plan -var-file="config/$(environment).tfvars" -compact-warnings
refresh:
cd terraform && terraform refresh -var-file="config/$(environment).tfvars" -compact-warnings
guided:
cd terraform && make guided
output:
cd terraform && terraform output
## Ansible
PRIVATE_KEY_PATH ?= ~/.ssh/id_rsa
.PHONY: playbook
playbook:
ansible-playbook ansible/playbook/$(playbook).yml -i ansible/inventory
## Utils
OUTPUT_FILE = ansible/inventory/hosts
TEMP_FILE = temp_ip.txt
ssh:
ssh -i $(PRIVATE_KEY_PATH) ubuntu@$(shell cd terraform && terraform output instance_public_dns)
update_host: temp_file populate clean_temp
temp_file:
cd terraform && terraform output instance_public_dns > $(TEMP_FILE)
populate:
echo "[aws_server]" > $(OUTPUT_FILE)
cat ./terraform/$(TEMP_FILE) >> $(OUTPUT_FILE)
echo "" >> $(OUTPUT_FILE)
echo "[aws_server:vars]" >> $(OUTPUT_FILE)
echo "ansible_ssh_user=ubuntu" >> $(OUTPUT_FILE)
echo "ansible_ssh_private_key_file=$(PRIVATE_KEY_PATH)" >> $(OUTPUT_FILE)
clean_inventory:
echo "[aws_server]" > $(OUTPUT_FILE)
echo "" >> $(OUTPUT_FILE)
echo "[aws_server:vars]" >> $(OUTPUT_FILE)
echo "ansible_ssh_user=ubuntu" >> $(OUTPUT_FILE)
echo "ansible_ssh_private_key_file=$(PRIVATE_KEY_PATH)" >> $(OUTPUT_FILE)
clean_temp:
rm ./terraform/$(TEMP_FILE)