Running Ansible from Jenkins in CentOS

Ansible is a radically simple IT automation system. It handles configuration management, application deployment, cloud provisioning, ad-hoc task execution, network automation, and multi-node orchestration. Ansible makes complex changes like zero-downtime rolling updates with load balancers easy.

Here in this blog we will see how we can configure Ansible with Jenkins.

What makes ansible different than many of the most popular configuration management systems is that its agent-less, no need to setup agents on every node you want to control.

Ansible Local Installation:

sudo yum-config-manager --enable epelsudo yum install ansible2

With that we have installed ansible. Now we will install Ansible plugin in Jenkins and configure the path of installed Ansible.

Ansible Plugin Installation

Go to Jenins -> Dashboard -> Manage Jenkins -> Manage Plugins -> Install Ansible Plugin

Configuring Jenkins and Ansible

We will set the path of locally installed Ansible in Jenkins.

Go to Jenkins -> Dashboard -> Manage Jenkins -> Global Tool Configuration -> Look for an option of Ansible.

Provide a name, and the path to your local Ansible installed.

To find the path of your local Ansible installation. Run this command on your terminal :

which ansible

With that we are good to run Ansible Playbooks from our Jenkins pipeline.

Sample Ansible playbook command :

ansiblePlaybook installation: 'ansible2', inventory: 'dev.inv', playbook: 'ansible.yml', disableHostKeyChecking: true

You can check my SpringBoot CICD pipeline GIT repository which uses Jenkins with Ansible for deployments :

This is how my configured CICD pipeline looks like in the above Git repo :

Happy Learning ! Cheers.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store