Closed rifaterdemsahin closed 6 years ago
AWS CODEDEPLOY CREATING REDIS USING ANSIBLE Step by step documentation about how to implement this:
Please make sure that you add the following files to your project for this to work appspec.yml the entire scripts folder
Step1:
Create CodeDeploy role attach the following policy(codedeployec2) in permissions:
// Policy Role for Code Deploy
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"autoscaling:PutLifecycleHook",
"autoscaling:DeleteLifecycleHook",
"autoscaling:RecordLifecycleActionHeartbeat",
"autoscaling:CompleteLifecycleAction",
"autoscaling:DescribeAutoscalingGroups",
"autoscaling:PutInstanceInStandby",
"autoscaling:PutInstanceInService",
"ec2:Describe"
],
"Effect": "Allow",
"Resource": ""
}
]
}
Attach the following policy in edit trust relationship.
// Policy Trust for Code Deploy
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "",
"Effect": "Allow",
"Principal": {
"Service": [
"codedeploy.us-west-2.amazonaws.com",
"codedeploy.us-east-1.amazonaws.com"
]
},
"Action": "sts:AssumeRole"
}
]
}
Create EC2CodeDeploy role like the above role and attach the following policy.
// Instance Role for EC2 Instance
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"s3:Get",
"s3:List"
],
"Effect": "Allow",
"Resource": "*"
}
]
}
Step2:
Create EC2 instance with following categories
a. Choose AMI: Amazon Linux AMI
b. Choose Instance type: t2.micro
c. Configure Instance: Choose EC2CodeDeploy IAM role
d. Tag Instance: Name it what you please
e. Configure Security Group:
HTTP TCP 80 0.0.0.0/0
HTTP TCP 80 ::/0
SSH TCP 22 (YOUR IP ADDRESS)
HTTPS TCP 443 0.0.0.0/0
HTTPS TCP 443 ::/0
f. LAUNCH INSTANCE
SSH into EC2 instance
Command line of Amazon Linux AMI
a. When server is booted
sudo su
yum -y update
yum install -y aws-cli
cd /home/ec2-user
b. Here you will setup your AWS access, secret, and region.
aws configure
aws s3 cp s3://aws-codedeploy-us-east-1/latest/install . --region us-east-1 (if in east AWS)
aws s3 cp s3://aws-codedeploy-us-west-2/latest/install . --region us-west-2 (if in west AWS)
chmod +x ./install
c. This is simply a quick hack to get the agent running faster.
sed -i "s/sleep(.*)/sleep(10)/" install
./install auto
d. Verify it is running.
service codedeploy-agent status
After successful completion of the above process we will get the code deploy agent status as below.
Step3: Open CodeDeploy service in AWS console and create a application and deployment group as following.
Choose the EC2 instance on which you want to deploy your application by selecting the instance tags .
After successful deployment of application you will get the page like below.
After deployment of the application we will get the following page.
Open the ec2 instance by using public ip of the instance in browser you will get the webpage which I have deployed using the code deploy.I have deployed web application using code deploy so I am getting this webpage.
Now our application is deploy,I want to install a redis server on this instance using a ansible playbook. Install Ansible locally and run the redis.yml which I have put in my github account. To run the playbook run the command: $ansible-plabook redis.yml Redis server will be installed on our instance.
This is the aws iam role creation.
HI,i have attached screenshots and step by step procedure
STEP 1 Create code deploy ( Screenshots ) STEP 2
Also include the necessary links for the reader to be able to go deep dive to the information