Create Ansible Role to install Jenkins on RHEL9

Mayank Jain
3 min readAug 4, 2023

--

Hello Folks, In the last blog we learned how to install Ansible on RHEL9 and run our first playbook using Ansible on the local machine.

In this blog we will learn how to create a ansible role and write a role to install Jenkins in RHEL9.

Prerequisites

RHEL9 OS, you can install on Virtual Box or if you are using the cloud then you can spin up the RHEL9 machine on it.

sudo user with Admin right on OS.

Ansible package should be installed on your machine. Refer here to install ansible on RHEL9.

Create Ansible Role for Jenkins installation

Create a working directory where you want to create and write the ansible role in you system. I am creating the directory playbooks in which we will write our ansible role.

# mkdir -p /home/mayank/workspace/learning/playbooks
# cd /home/mayank/workspace/learning/
# ls
Dir structure

Once the directory is create we will run the below command to create a initial directory structure of role.

# ls playbooks/jenkins/

Understanding the directories

Each directory must contain a main.yml file which contains relevant content. Let’s look little closer to each directory.

defaults: Contains default variables for the role. Variables in default have the lowest priority so they are easy to override.

files: Contains files which we want to be copied to the remote host. We don’t need to specify a path of resources stored in this directory.

handlers: Contains handlers which can be invoked by “notify” directives and are associated with service.

meta: Contains metadata of role like an author, support platforms, dependencies.

tasks: Contains the main list of steps to be executed by the role.

templates: Contains file template which supports modifications from the role. We will use the Jinja2 template (.j2) language for creating templates.

tests: This folder contains a test environment with an inventory file and a playbook script to test the role.

vars: Contains variables for the role. Variables in vars have higher priority than variables in defaults directory.

Now once the ansible role is created using ansible-galaxy command you can refer my git repository here to get the complete code of the role of jenkins installation.

Refer here to learn How to set up Puppet Master and Agent in a Virtual Box environment.

Refer here to learn How to write modules in Puppet.

Learn RHEL8 custom AMI creation using RHEL Image Builder here.

--

--

Mayank Jain

Skilled DevOps Engineer with 7.5+ years of hands-on experience supporting, automating, & optimizing mission critical deployments in cloud.