2021-12-26 13:19:05 -08:00
|
|
|
|
2021-12-27 08:58:52 -08:00
|
|
|
SSH := ssh -o "StrictHostKeyChecking=no" -o UserKnownHostsFile=/dev/null -o ProxyCommand="sh -c \"aws ssm start-session --target %h --document-name AWS-StartSSHSession --parameters portNumber=%p\"" -i privkey.pem -l ubuntu
|
2021-12-26 13:19:05 -08:00
|
|
|
|
2021-12-27 08:58:52 -08:00
|
|
|
default: terraform ansible
|
2021-12-26 13:19:05 -08:00
|
|
|
|
2022-01-01 14:54:25 -08:00
|
|
|
# I can't be relied on to remember the command to connect to the instance
|
2022-01-02 08:37:22 -08:00
|
|
|
ssh: setup
|
2022-01-01 14:54:25 -08:00
|
|
|
$(SSH) $(INSTANCE)
|
|
|
|
|
2022-01-02 08:37:22 -08:00
|
|
|
setup:
|
|
|
|
$(eval INSTANCE := $(shell terraform output instance_id | sed -e 's/"//g'))
|
|
|
|
$(eval PUBLIC_IP := $(shell terraform output public_ip | sed -e 's/"//g'))
|
2021-12-27 08:58:52 -08:00
|
|
|
chmod 600 privkey.pem
|
|
|
|
|
2022-01-02 08:37:22 -08:00
|
|
|
ansible: setup
|
2022-01-02 18:32:29 -08:00
|
|
|
timeout --foreground 300 bash -c -- 'until $(SSH) $(INSTANCE) "/bin/true"; do sleep 0.5; done'
|
2021-12-27 08:58:52 -08:00
|
|
|
$(SSH) $(INSTANCE) "which -a ansible || (sudo apt-get update && sudo apt-get -y install ansible)"
|
2022-01-02 08:37:22 -08:00
|
|
|
sed \
|
|
|
|
-e 's/{{INSTANCE}}/$(INSTANCE)/' \
|
|
|
|
-e 's/{{PUBLIC_IP}}/$(PUBLIC_IP)/' \
|
|
|
|
inventory.tmpl.ini > inventory.ini
|
2021-12-27 08:58:52 -08:00
|
|
|
ansible-playbook -i inventory.ini --private-key privkey.pem -l nextcloud site.yaml
|
|
|
|
|
|
|
|
terraform:
|
2021-12-26 17:38:18 -08:00
|
|
|
terraform init
|
|
|
|
terraform apply
|
|
|
|
|
2022-01-02 08:37:22 -08:00
|
|
|
.PHONY: setup ansible terraform
|
2021-12-26 17:38:18 -08:00
|
|
|
|