include ../config.mk include ../terraform/terraform.mk # I don't remember why I had this at all: #AWS_REGION = $(AWS_REGION) SSH := ssh -o "StrictHostKeyChecking=no" -o UserKnownHostsFile=/dev/null -o ProxyCommand="sh -c \"aws --region $(AWS_REGION) ssm start-session --target %h --document-name AWS-StartSSHSession --parameters portNumber=%p\"" -i ../terraform/privkey -l ubuntu default: ansible ansible: toolcheck inventory.yaml @echo @echo Attempting to configure to the target host. This might take a few tries the first time. @echo timeout --foreground 300 bash -c -- 'until $(SSH) $(INSTANCE_ID) "/bin/true"; do sleep 0.5; done' export ANSIBLE_NOCOWS=1; ansible-playbook -i inventory.yaml --private-key ../terraform/privkey -l social site.yaml ssh: inventory.yaml $(SSH) $(INSTANCE_ID) reboot: inventory.yaml aws --region $(AWS_REGION) ec2 reboot-instances --instance-ids $(INSTANCE_ID) inventory.yaml: inventory.tmpl.yaml sedline sed $(SEDLINE) inventory.tmpl.yaml > inventory.yaml SEDLINE = sedline: terraform_sedline config_sedline secret_sedline config_sedline: $(addprefix __sed_,$(shell grep '^[0-9A-Z_]' ../config.mk | awk '{print $$1}')) terraform_sedline: $(addprefix __sed_,$(shell grep '^[0-9A-Z_]' ../terraform/terraform.mk | awk '{print $$1}')) __sed_%: $(eval SEDLINE := $$(SEDLINE) -e 's/{{$*}}/$($*)/') # FIXME: this is awful because it's all in the clear secret_sedline: $(eval SEDLINE := $$(SEDLINE) -e 's/{{S3_IAM_ID}}/$(shell head -1 ../.s3_iam_credentials)/') $(eval SEDLINE := $$(SEDLINE) -e 's/{{S3_IAM_SECRET}}/$(shell tail -1 ../.s3_iam_credentials)/') $(eval SEDLINE := $$(SEDLINE) -e 's/{{SES_IAM_ID}}/$(shell head -1 ../.ses_iam_credentials)/') $(eval SEDLINE := $$(SEDLINE) -e 's/{{SES_IAM_SECRET}}/$(shell ./ses_credentials.py `tail -1 ../.ses_iam_credentials` $(AWS_REGION) | sed -e "s/\//\\\\\//g")/') # FIXME: DRY this target CHECK_TOOLS = ansible toolcheck: @echo @echo "Checking applications..." @ FAIL=""; \ for TOOL in $(CHECK_TOOLS); do \ which $${TOOL} >/dev/null || FAIL="$${FAIL} $${TOOL}"; \ done; \ if test -n "$${FAIL}"; then \ echo "ERROR: You are missing the following:$${FAIL}"; \ echo "Please make sure all necessary tools are installed and available in your path"; \ echo; \ exit 1; \ fi @echo mkdir -p credentials/mastodon