FoxuTech

How to Run a ansible playbook using jenkins

How to Run a ansible playbook using jenkins

The aim of this post is to demonstrate how to use Ansible for environment provisioning and application deployment in a Continuous Integration/Continuous Delivery (CI/CD) process using a Jenkin

Ansible is a powerful tool for IT automation and can be used in a CI/CD process to provision the target environment and to then deploy the application on it.

Jenkins is a well-known tool for implementing CI/CD. Shell scripts are commonly used for provisioning environments or to deploy apps during the pipeline flow. Although this could work, it is cumbersome to maintain and reuse scripts in the long run.

Useful Links:

Jenkisn UI Console:

Step 1: Install ansible plugin using Manage Jenkins Plugins console

Step 2: Configure the ansible installation configuration in Jenkins “Global Tool Configuration” as shown in below pic.

Note: Path of the ansible installed in Jenkins can be found with the below command.

# which ansible
/usr/bin/ansible.

Playbook/ansible commands executed correctly when i gave ‘/usr/bin’ in the “path of ansible executable directory”.

step 3: Configure the Jenkins job.

In build step of Jenkins job, select “Invoke Ansible Playbook” and specify the entries of Ansible installation name, playbook path, inventory file path, host subset pattern and the user to execute the command as shown in the below picture.

Note: In host subset entry to limit the group of servers the playbook executed -do not provide quotes as we do in regular playbook command ‘${group}’ /’hostname’. Just provide ${group} /hostname without quotes. It’s the default behavior for Jenkins-ansible plugin.

Note: You can use vault passwords too.

Read More: Install jenkins using Ansible

Advantages of Using Jenkins

What else is great about using Jenkins to deploy your code? Here’s some quick hits:

Exit mobile version