Saturday, February 10, 2024

Install Jenkins using Ansible Role on Ubuntu | Install Jenkins using Ansible Role | How to Setup Jenkins using Ansible

Find below Ansible Role for installing Jenkins on a Ubuntu machine.

Java needs to be installed already on machine before setting up Jenkins. please Click here for Java Playbook. Here below is the Ansible Role for installing Jenkins using Ansible in Ubuntu EC2:

cd ~/roles
sudo vi aws-infra-role/tasks/installJenkins.yml

Copy the below yellow highlighted in the above file: 

    - name: ensure the jenkins apt repository key is installed
      apt_key: url= state=present
      become: yes

    - name: ensure the repository is configured
      apt_repository: repo='deb binary/' state=present
      become: yes

    - name: ensure jenkins is installed
      apt: name=jenkins update_cache=yes
      become: yes

    - name: ensure jenkins is running
      service: name=jenkins state=started

Modify Hosts/Inventory file
sudo vi /etc/ansible/hosts
make sure you add below entry with target node IP changed (in red color).
xx.xx.xx.xx ansible_ssh_user=ubuntu ansible_ssh_private_key_file=~/.ssh/id_rsa  ansible_python_interpreter=/usr/bin/python3

Modify Ansible main playbook

sudo vi aws-infra-role/setup-jenkins.yml
# This Playbook creates infra in aws cloud

- hosts: My_Group
  gather_facts: False
  tags: jenkins creation

  - include: tasks/installJava11.yml
  - include: tasks/installMaven.yml
  - include: tasks/installJenkins.yml

Execute Ansible Role
ansible-playbook aws-infra-role/setup-jenkins.yml

This should install Jenkins on the target node.

Now enter public ip address or public dns name with port no 8080 of target server by in the browser to see Jenkins up and running.


No comments:

Post a Comment

DevOps Bootcamp Aug 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 and Monitoring..) The DevOps requirements in the IT market space is expected to grow ...