Saturday, December 31, 2022

How to run Ansible playbook from Jenkins pipeline job | Automate EC2 provisioning in AWS using Jenkins and Ansible Playbook | Create new EC2 instance in AWS cloud using Ansible Playbook and Jenkins Pipeline

We will learn how to create new EC2 instance using Ansible playbook and automate using Jenkins Pipeline. 

Watch Steps in YouTube Channel:

Pre-requisites:

  • Ansible is installed and Boto is also installed on Jenkins instance
  • Ansible plug-in is installed in Jenkins. 
  • Make sure you create an IAM role with AmazonEC2FullAccess policy and attach the role to Jenkins EC2 instance.
  • Playbook for creating new EC2 instance needs to be created but you can refer my GitHub Repo
Steps:

Create Ansible playbook for provisioning EC2 instance

(Sample playbook is available in my GitHub Repo, you can use that as a reference)

Create Jenkins Pipeline 
pipeline {
    agent any

    stages {
        
        stage ("checkout") {
            steps {
                        checkout([$class: 'GitSCM', branches: [[name: '*/master']], extensions: [],                                                     userRemoteConfigs: [[url: 'https://github.com/akannan1087/myAnsibleInfraRepo']]])         
            }
        }
        stage('execute') {
            steps {
                //to suppress warnings when you execute playbook    
                sh "pip install --upgrade requests==2.20.1"
                // execute ansible playbook
                ansiblePlaybook playbook: 'create-EC2.yml'
            }
        }
    }
}

Execute Pipeline


Pipeline Console output


No comments:

Post a Comment

DevOps Bootcamp Oct 2024 Schedule | DevOps & AWS Azure Cloud Coaching by Coach AK | DevOps and Cloud Computing Online Classes

  (Lot of new topics covered like GitHub Actions, Helm, Prometheus and Grafana..) The DevOps requirements in the IT market space is expected...