How to install Jenkins using Ansible on ubuntu.

Reading Time: 3 minutes
From Zero to Code: Using Ansible in Jenkins Pipelines.


Jenkins is a Continuous Integration tool that allows continuous development test and deployment of newly created code and as its written in java.


Ansible is an open source tool that really allows to create and control three key areas that you’d have within your operations environment:

  1. IT automation
  2. Configuration management
  3. Automatic deployment

I will show you how to install Jenkins on your local machine using Ansible playbook.

Ansible roles

  • Ansible Role are consists of many playbooks, which is similar to modules in puppet and cook books in chef. We term the same in ansible as roles.
  • Roles are a way to group multiple tasks together into one container to do automation in very effective manner with clean directory structures.
  • It can be easily reuse the codes by anyone if the role is suitable to someone.
Step 1:
  • Create jenkins.yml – playbook for Jenkins installation.
  • The “hosts” line in the playbook is a list of one or more groups or host patterns.
  • In this post, we have localhost. That means we are going to apply this playbook on localhost only.
  • Next is roles.
  • Roles are ways of automatically loading certain vars_files, tasks, and handlers based on a known file structure. (In next step we are going to create directory structure for role).
  • Grouping content by roles also allows easy sharing of roles with other users.
  • Tags are useful if you have a large playbook, and want to run a specific part of the configuration without running the whole playbook.

Step 2:

  • Parallel to jenkins.yml create a ‘roles’ directory in which all our roles reside.
  • Now lets create directory structure for roles using ansible-galaxy command.
  • The ansible-galaxy command comes bundled with Ansible, we are using it here to create basic directory layout for our Jenkins role.

Step 3 :

  • Roles expect files to be in certain directory names. Each directory must contain a main.yml file. Below is a description of each directory.

tasks – contains the main list of tasks to be executed by the role.

handlers – contains handlers, which may be used by this role or even anywhere outside this role.

defaults – default variables for the role.

vars – other variables for the role.

files – contains files which can be deployed via this role.

templates – contains templates which can be deployed via this role.

meta – defines some meta data for this role.

Step 4:

  • Lets take a look at the jenkins.yml file. We have included all the Jenkins tasks here.
  • Starting with downloading java, Jenkins, installing and configuring Jenkins and finally starting the Jenkins service and enabling it to start on reboot.

We have included the jenkins.yml file in the jenkins/tasks/main.yml file.

  • We are using variables here. The values for installing of java and using apt repository etc are all place in the jenkins/vars/main.yml file as shown below.
  • To run the Ansible Playbook using this command.

ansible-playbook install-jenkins.yml -i inventory.ini

Post -installation Jenkins setup
  1. Navigate to http://<jenkins public ip>:8080
    (replace <jenkins public ip> with your own)

Written by 

I am an enthusiastic , hard-working and determine girl with strong attention to detail and eager to learn about new technologies.