-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.sh
executable file
·48 lines (36 loc) · 1.17 KB
/
run.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
cd terraform
terraform init
terraform apply
if [ $? -ne 0 ]
then
echo "Error During Terraform Execution, Failed Run!"
exit $?
fi
cd ..
bastion_host_ip=$(awk -F= '{if($1=="bastion_host_ip") {print $2;exit}}' outputs.txt)
cluster_name=$(awk -F= '{if($1=="cluster_name") {print $2;exit}}' outputs.txt)
if [[ ! $bastion_host_ip || ! $cluster_name ]]
then
echo "Empty Variables, Failed Run!"
exit 1
fi
cat <<EOF > ansible/inventory
[bastion]
$bastion_host_ip
EOF
echo "The inventory has been updated!"
workernodes_asg=$(aws eks describe-nodegroup \
--cluster-name private_eks \
--nodegroup-name private_eks_ng \
--query 'nodegroup.resources.autoScalingGroups[]' \
--output text)
instance_id=$(aws autoscaling describe-auto-scaling-groups \
--auto-scaling-group-names $workernodes_asg \
--query 'AutoScalingGroups[].Instances[0].InstanceId' \
--output text)
instance_host_name=$(aws ec2 describe-instances \
--instance-ids $instance_id \
--query 'Reservations[].Instances[].PrivateDnsName' \
--output text)
echo "Starting Playbook Now..."
ansible-playbook ansible/playbook.yml -e "cluster_name=${cluster_name}" -e "workernode_hostname=${instance_host_name}" --ask-vault-pass