-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathansible-init.sh
More file actions
32 lines (23 loc) · 1.09 KB
/
Copy pathansible-init.sh
File metadata and controls
32 lines (23 loc) · 1.09 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
#!/bin/bash
set -euo pipefail
AWS_REGION="us-east-1"
sudo install -d -m 700 -o ec2-user -g ec2-user /home/ec2-user/.ssh
aws ssm get-parameter \
--name "/terraform-aws-ansible-project/ansible/ssh-private-key" \
--with-decryption \
--query "Parameter.Value" \
--region "$AWS_REGION" | tee ~/.ssh/aws-key.pem >/dev/null
sudo chown ec2-user:ec2-user /home/ec2-user/.ssh/aws-key.pem
sed -i 's/^"//; s/"$//; s/\\n/\n/g; s/\r$//' ~/.ssh/aws-key.pem
sudo chmod 600 /home/ec2-user/.ssh/aws-key.pem
ansible-galaxy collection install community.docker amazon.aws ansible.posix
cd ansible
ansible-inventory -i inventory_aws_ec2.yml --graph
ansible-playbook -i inventory_aws_ec2.yml playbooks/install.yml
ALB_ARN=$(aws elbv2 describe-target-groups \
--region us-east-1 \
--names backend-target-group \
--query 'TargetGroups[0].LoadBalancerArns[0]' \
--output text)
API_BASE_URL="http://$(aws elbv2 describe-load-balancers --load-balancer-arns "$ALB_ARN" --query 'LoadBalancers[0].DNSName' --output text --region "$AWS_REGION" )" \
ansible-playbook -i inventory_aws_ec2.yml playbooks/deploy.yml