Posts

Showing posts from April, 2023

Ansible Playbook for provisioning a new EC2 instance in AWS | Create new EC2 instance in AWS cloud using Ansible Playbook

Image
We will learn how to create Ansible Playbook for provisioning a new EC2 instance in AWS cloud. Please follow the below steps in the machine where you have installed Ansible. Pre-requisites: Ansible is installed and Boto is also installed  on Ubuntu EC2 instance Create an IAM role with AmazonEC2FullAccess policy in AWS console and attach the role to ansible EC2 instance. Steps to create EC2 instance using Ansible: Login to EC2 instance using Git bash or ITerm/putty where you installed Ansible. Execute the below command: Create an Inventory file first sudo mkdir /etc/ansible Edit Ansible hosts or inventory file sudo vi /etc/ansible/hosts Add the below two lines in the end of the file: [localhost] local cd ~ mkdir playbooks     cd playbooks Create Ansible playbook sudo vi create_ec2.yml  (copy the below content  in  green  color) edit the create_jenkins_ec2.yml to make sure you update the key which is red marked below: ---   - name:    provisioning EC2 instances using Ansible     hosts: l

Install Ansible on Ubuntu | How to setup Ansible on Ubuntu 22.0.4 | Ansible install on Ubuntu

Image
Ansible is #1 configuration management tool. It can also be used for  infrastructure   provisioning  as well. or You can use Ansible in combination of Terraform which can take care of infra automation and Ansible can do  configuration  management.   Ansible Architecture:   The best way to install Ansible for Ubuntu is to add the project's PPA (personal package archive) to your system. You also would need Boto framework for provisioning resources in AWS cloud. Pre-requisites Create new Ubuntu EC2 instance for installing Ansible, just open port 22. Change Host Name to AnsibleMgmtNode sudo hostnamectl set-hostname  AnsibleMgmtNode Update Repository sudo apt-get update Install Ansible: sudo apt install ansible sudo apt install python3-pip -y  ( this is just comment -  Package manager for python) Install Boto Framework - AWS SDK sudo pip3 install boto boto3 Ansible will access AWS resources using boto SDK. sudo apt-get install python3-boto -y pip list boto | grep boto (the above command

How to configure Declarative Pipeline - Creating Jenkinsfile in GitHub

Image
Please find steps below for configuring pipeline as a code - Jenkinsfile. Pre-requistes: 1. Project setup in Bitbucket/GitHub/GitLab 2. Jenkins and Tomcat (web container) set up. 3. Maven installed in Jenkins 4. Sonarqube setup and integrated with Jenkins 5. Nexus configured and integrated with Jenkins 6. Slack channel configured an integrated with Jenkins Create Jenkinsfile (pipeline code) to your MyWebApp Step 1 Go to GitHub and choose the Repo where you setup MyWebApp Step 2 Click on Add file then create new file. Step 3 - Enter  Jenkinsfile  as a file name Step 4 Copy and paste the below code and make sure what ever is highlighted in red color needs to be changed per your settings. That's it. Pipeline as a code - Jenkinsfile is setup in GitHub. To make things easy, work stage by stage. pipeline {   agent any     tools {   maven ' Maven3 '   }   stages {     stage ('Build') {       steps {       sh 'mvn clean install -f MyWebApp/pom.xml'       }     }    

Scripted Pipeline in Jenkins

Image
 What are Pipelines in Jenkins? - Pipelines are  better than freestyle jobs , you can write a lot of complex tasks using pipelines when compared to Freestyle jobs. - You can see  how long each stage takes time to execute  so you have more control compared to freestyle. - Pipeline is groovy based script  that have set of plug-ins integrated for automating the builds, deployment and test execution. - Pipeline defines  your entire build process, which typically includes stages for building an application, testing it and then delivering it .   - You can use  snippet generator  to generate pipeline code for the stages you don't know how to write groovy code. Pre-requisites: Install plug-ins 1. Install Deploy to container, Slack, Jacoco, Nexus Artifact Uploader and SonarQube plug-ins (if already installed, you can skip it) Steps to Create Scripted Pipeline in Jenkins 1. Login to Jenkins 2. Create a New item 3. Give name as MyfirstPipelineJob and choose pipeline 4. Click ok. Pipeline is c

Difference between Scripted and Declarative Pipelines

Difference between Scripted and Declarative Pipelines Scripted Pipelines are written in Groovy scripting language, and provide a great degree of flexibility and control over the pipeline's execution. The pipeline definition is written as a script that is executed by the Jenkins Pipeline plugin. It allows the use of imperative programming constructs, such as loops and conditions, which makes it easy to define complex logic. On the other hand, Declarative Pipelines provide a simpler and more structured way to define pipelines. They are defined using a declarative syntax, which is a set of predefined keywords and constructs that describe the pipeline's steps and stages. The declarative syntax is easier to read and understand, and promotes best practices such as defining stages, post-build actions, and error handling. Some differences between Scripted and Declarative Pipelines are: Syntax: Scripted Pipelines use a scripting syntax while Declarative Pipelines use a declarative synta

Setup build agent/slave VM and Integrate with Jenkins Master

Image
Jenkins has powerful feature of master slave architecture which enables distributed builds. This article we will learn how to establish slave nodes on Ubuntu machines and integrate with Jenkins Master. Jenkins Master Your main Jenkins server is the Master. The Master’s job is to handle: Scheduling build jobs. Dispatching builds to the slaves for the actual execution. Monitor the slaves (possibly taking them online and offline as required). Recording and presenting the build results. A Master instance of Jenkins can also execute build jobs directly. Jenkins Slave A Slave is a Java executable that runs on a remote machine. Following are the characteristics of Jenkins Slaves: It hears requests from the Jenkins Master instance. Slaves can run on a variety of operating systems. The job of a Slave is to do as they are told to, which involves executing build jobs dispatched by the Master. You can configure a project to always run on a particular Slave machine, or a particular type of Slave ma