In order to see list of signed requests in Puppet Master, execute the below command to view the signed certs:
/opt/puppetlabs/bin/puppet cert list --all
Hands on DevOps Coaching provided using AWS & Azure Cloud. please contact Coach AK at devops.coaching@gmail.com for more info.
Monday, April 9, 2018
Ansible playbook for installing Apache on Redhat Linux
---
- hosts: Apache_Group
become: true
tasks:
- name: install the latest version of Apache
yum:
name: httpd
state: latest
- name: ensure apache started
service: name=httpd state=started enabled=yes
- hosts: Apache_Group
become: true
tasks:
- name: install the latest version of Apache
yum:
name: httpd
state: latest
- name: ensure apache started
service: name=httpd state=started enabled=yes
How to do deployment to Tomcat using Pipeline in Jenkins
Please follow below steps for deploying WARs into Tomcat that is setup on a different machine.
Pre-requistes:
1. install ssh agent plugin in Jenkins master.
2. create ssh-keys in by executing the below command:
ssh-keygen
make sure you copy ssh public keys in target node where tomcat server is running.
3. also make sure you give permission to upload the WAR in by following command:
sudo chown ubuntu:ubuntu /var/lib/tomcat8/webapps/
Deployment steps:
Step 1:
Go to Jenkins, Add credentials. Select SSH username with private key. enter source machine SSH private keys. enter username as jenkins or ubuntu. Click OK
step 2: Go to Jenkins, Credentials, now copy the ID of the entry you made.
Step 3: Go to Pipeline: use the above ID in deploy stage and also make sure you enter target server ip address.
node {
-------
stage ('Deploy') {
echo "deploying to DEV tomcat "
sshagent(['15a9ed22-6dcb-4916-8536-bde265de07e8']) {
sh 'scp -o StrictHostKeyChecking=no /var/lib/jenkins/workspace/$JOB_NAME/MyWebApp/target/MyWebApp.war ubuntu@server_ip:/var/lib/tomcat8/webapps'
}
}
}
Pre-requistes:
1. install ssh agent plugin in Jenkins master.
2. create ssh-keys in by executing the below command:
ssh-keygen
make sure you copy ssh public keys in target node where tomcat server is running.
3. also make sure you give permission to upload the WAR in by following command:
sudo chown ubuntu:ubuntu /var/lib/tomcat8/webapps/
Deployment steps:
Step 1:
Go to Jenkins, Add credentials. Select SSH username with private key. enter source machine SSH private keys. enter username as jenkins or ubuntu. Click OK
step 2: Go to Jenkins, Credentials, now copy the ID of the entry you made.
Step 3: Go to Pipeline: use the above ID in deploy stage and also make sure you enter target server ip address.
node {
-------
stage ('Deploy') {
echo "deploying to DEV tomcat "
sshagent(['15a9ed22-6dcb-4916-8536-bde265de07e8']) {
sh 'scp -o StrictHostKeyChecking=no /var/lib/jenkins/workspace/$JOB_NAME/MyWebApp/target/MyWebApp.war ubuntu@server_ip:/var/lib/tomcat8/webapps'
}
}
}
Friday, April 6, 2018
How to provision EC2 using AWS CloudFormation templates in Ubuntu
AWS comes with CloudFormation template for creating resources in AWS using code. You can create any resources using CloudFormation. Let us try to create an EC2 using AWS CLI in Ubuntu.
pre-requistes:
AWS CLI needs to be installed. It can be installed by executing below command:
sudo apt install awscli
Steps:
Login to Ubuntu instance. create the below file with content
sudo vi create-jenkins-ec2.xml
AWSTemplateFormatVersion: 2010-09-09
Resources:
MyJenkinsSG:
Type: 'AWS::EC2::SecurityGroup'
Properties:
GroupDescription: Jenkins Security Group
GroupName: Jenkins-security-group
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 22
ToPort: 22
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: 80
ToPort: 80
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: 8080
ToPort: 8080
CidrIp: 0.0.0.0/0
MyEc2Instance:
Type: 'AWS::EC2::Instance'
Properties:
KeyName: myKey
AvailabilityZone: us-east-2b
ImageId: ami-916f59f4
SecurityGroupIds:
- !Ref MyJenkinsSG
InstanceType: t2.micro
Tags:
- Key: MyEc2
Value: JenkinsEC2
After saving the file,
You may have to give AWS access key, security keys and region code by running
aws configure
AWS Access Key ID [None]:
AWS Secret Access Key [None]:
Default region name [None]:
Then execute the below command:
aws cloudformation create-stack --stack-name myjenkinsstack --template-body file:///create-jenkins-ec2.xml
Now check in AWS Mgmt console to see if EC2 is created.
pre-requistes:
AWS CLI needs to be installed. It can be installed by executing below command:
sudo apt install awscli
Steps:
Login to Ubuntu instance. create the below file with content
sudo vi create-jenkins-ec2.xml
AWSTemplateFormatVersion: 2010-09-09
Resources:
MyJenkinsSG:
Type: 'AWS::EC2::SecurityGroup'
Properties:
GroupDescription: Jenkins Security Group
GroupName: Jenkins-security-group
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 22
ToPort: 22
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: 80
ToPort: 80
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: 8080
ToPort: 8080
CidrIp: 0.0.0.0/0
MyEc2Instance:
Type: 'AWS::EC2::Instance'
Properties:
KeyName: myKey
AvailabilityZone: us-east-2b
ImageId: ami-916f59f4
SecurityGroupIds:
- !Ref MyJenkinsSG
InstanceType: t2.micro
Tags:
- Key: MyEc2
Value: JenkinsEC2
After saving the file,
You may have to give AWS access key, security keys and region code by running
aws configure
AWS Access Key ID [None]:
AWS Secret Access Key [None]:
Default region name [None]:
Then execute the below command:
aws cloudformation create-stack --stack-name myjenkinsstack --template-body file:///create-jenkins-ec2.xml
Now check in AWS Mgmt console to see if EC2 is created.
Wednesday, April 4, 2018
Provision EC2 instance in AWS using Terraform - Create Terraform files for provisioning resources on AWS
Terraform can provision resources on any cloud platform. We will see how you can use Terraform to provision EC2 instance.
1. Login to AWS console, click on username and go to My security credentials. 2. Continue on security credentials, click on access keys 3. Create a new access key if you don't have one. Make sure you download the keys.
4. create aws.tf file with below content. make sure you update with your Access key and secret keys.
replace red marked with keys you received from step # 3 above.
sudo vi aws.tf
access_key = "xx"
secret_key = "xx"
region = "us-east-2"
}
1. Login to AWS console, click on username and go to My security credentials. 2. Continue on security credentials, click on access keys 3. Create a new access key if you don't have one. Make sure you download the keys.
4. create aws.tf file with below content. make sure you update with your Access key and secret keys.
replace red marked with keys you received from step # 3 above.
sudo vi aws.tf
provider "aws" {
secret_key = "xx"
region = "us-east-2"
}
Now execute the below command:
terraform init
the above command should load the AWS plug-ins.
sudo vi create_ec2.tf
copy the below code in yellow color:
resource "aws_instance" "myFirstInstance" {
ami = "ami-916f59f4"
key_name = "my_key"
instance_type = "t2.micro"
security_groups= [ "security_jenkins_grp"]
ami = "ami-916f59f4"
key_name = "my_key"
instance_type = "t2.micro"
security_groups= [ "security_jenkins_grp"]
tags= {
Name = "jenkins_instance"
}
Name = "jenkins_instance"
}
}
resource "aws_security_group" "security_jenkins_grp" {
name = "security_jenkins_grp"
description = "security group for jenkins"
ingress {
from_port = 8080
to_port = 8080
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
# outbound from jenkis server
egress {
from_port = 0
to_port = 65535
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
tags= {
Name = "security_jenkins_grp"
}
}
resource "aws_security_group" "security_jenkins_grp" {
name = "security_jenkins_grp"
description = "security group for jenkins"
ingress {
from_port = 8080
to_port = 8080
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
# outbound from jenkis server
egress {
from_port = 0
to_port = 65535
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
tags= {
Name = "security_jenkins_grp"
}
}
terraform plan
the above command will show you what Terraform is going to do..
the above command will show you what Terraform is going to do..
terraform apply
type yes
Now login to EC2 console to see newly provisioned EC2 instance.
Now login to EC2 console to see newly provisioned EC2 instance.
Tuesday, April 3, 2018
Install Docker from Ubuntu Repositories
You can install Docker from Ubuntu repositories.
sudo apt-get update
sudo apt-get install -y docker.io
Docker —version
Docker version 1.13.1, build 092cba3
sudo docker run hello-world
sudo apt-get update
sudo apt-get install -y docker.io
Docker —version
Docker version 1.13.1, build 092cba3
sudo docker run hello-world
Subscribe to:
Posts (Atom)
-
Let's learn how to connect to an EC2 instance running in AWS from your local machine. Your local machine can be Windows laptop or MacBoo...
-
We get these questions a lot from the teams we are coaching at my customer's work place How to create microservices? How to break...
-
Amazon Elastic Container Registry (ECR) is a fully managed container registry service provided by Amazon Web Services (AWS). It allows user...

