-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprovisioning_script.sh
executable file
·67 lines (63 loc) · 5.3 KB
/
provisioning_script.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#! /usr/bin/bash
YELLOW='\e[33m'
GREEN='\033[0;32m'
NC='\033[0m'
RED='\e[31m'
echo -e "${YELLOW}******************************************************************************************************************************************************${NC}"
echo -e "${YELLOW}******************************************************************************************************************************************************${NC}"
echo -e "${YELLOW}------------------------------------------------------------------------------------------------------------------------------------------------------${NC}"
echo -e "${YELLOW}-----------------------------------------------------------------//-Installing Required Tools-//------------------------------------------------------${NC}"
echo -e "${YELLOW}------------------------------------------------------------------------------------------------------------------------------------------------------${NC}"
echo ""
read -p "To proceed, we need to install the required tools. Would you like to proceed? (y/n): " confirm
if [ "$confirm" = "y" ]; then
./setup/setup.sh
else
echo -e "${RED}Skipping..."
fi
echo -e "${YELLOW}------------------------------------------------------------------------------------------------------------------------------------------------------${NC}"
echo -e "${YELLOW}-----------------------------------------------------------------//-Configuring AWS Credentials-//----------------------------------------------------${NC}"
echo -e "${YELLOW}------------------------------------------------------------------------------------------------------------------------------------------------------${NC}"
echo ""
./awscreds.sh
echo ""
echo -e "${YELLOW}------------------------------------------------------------------------------------------------------------------------------------------------------${NC}"
echo -e "${YELLOW}-----------------------------------------------------------------//-Configuring SSH Keys-//-----------------------------------------------------------${NC}"
echo -e "${YELLOW}------------------------------------------------------------------------------------------------------------------------------------------------------${NC}"
echo ""
rm -rf ~/.ssh/known_hosts
./sshkeys.sh
echo ""
echo -e "${YELLOW}------------------------------------------------------------------------------------------------------------------------------------------------------${NC}"
echo -e "${YELLOW}-----------------------------------------------------------------//-Setting up vault server-//-----------------------------------------------------------${NC}"
echo -e "${YELLOW}------------------------------------------------------------------------------------------------------------------------------------------------------${NC}"
echo ""
./vault/vault.sh
echo ""
echo -e "${YELLOW}------------------------------------------------------------------------------------------------------------------------------------------------------${NC}"
echo -e "${YELLOW}-----------------------------------------------------------------//-Running Terraform-//--------------------------------------------------------------${NC}"
echo -e "${YELLOW}------------------------------------------------------------------------------------------------------------------------------------------------------${NC}"
echo ""
terraform -chdir=terraform init
terraform -chdir=terraform apply -auto-approve
echo ""
echo -e "${GREEN}Instances Created Successfully.${NC}"
echo -e "${YELLOW}------------------------------------------------------------------------------------------------------------------------------------------------------${NC}"
echo -e "${YELLOW}-----------------------------------------------------------------//-Configuring /etc/hosts-//---------------------------------------------------------${NC}"
echo -e "${YELLOW}------------------------------------------------------------------------------------------------------------------------------------------------------${NC}"
echo ""
sudo sed -i '/prod/d; /remote_jenkins/d' /etc/hosts
sudo sed -i -e '$a\'"$(terraform -chdir=./terraform output -raw jenkins_public_ip) remote_jenkins" /etc/hosts
sudo sed -i -e '$a\'"$(terraform -chdir=./terraform output -raw prod_public_ip) production_server" /etc/hosts
echo ""
echo -e "${GREEN}/etc/hosts File Successfully Configured.${NC}"
echo -e "${YELLOW}------------------------------------------------------------------------------------------------------------------------------------------------------${NC}"
echo -e "${YELLOW}-----------------------------------------------------------------//-Running Ansible Playbooks-//------------------------------------------------------${NC}"
echo -e "${YELLOW}------------------------------------------------------------------------------------------------------------------------------------------------------${NC}"
echo ""
cd ansible
ansible-playbook --private-key ~/.ssh/jenkins jenkins.yml -vvv
ansible-playbook --private-key ~/.ssh/prod jenkins2.yml
echo ""
echo -e "${YELLOW}******************************************************************************************************************************************************${NC}"
echo -e "${YELLOW}******************************************************************************************************************************************************${NC}"