DEV Community

Maureen Chebet
Maureen Chebet

Posted on

Configure Jenkins using Ansible on Amazon Linux 2023

Image description

Overview

Jenkins is a powerful automation server that can be used for continuous integration and continuous delivery (CI/CD) pipelines. Ansible is a popular configuration management tool that allows you to automate the provisioning and configuration of infrastructure. In this article, we'll explore how to use Ansible to configure Jenkins on Amazon Linux in the year 2023.

Prerequisites
Before we begin, make sure you have basic knowledge of Ansible and Jenkins and the following prerequisites:

  • An AWS account
  • An Amazon Linux instance up and running. (Amazon Linux 2023)
  • SSH access to your Amazon Linux instance.

Note: Make sure to open the necessary ports (e.g., port 8080 for Jenkins) in the security group settings.

Step 2: Install Ansible

Connect into the ec2 instance either using ssh or session manager the run:
sudo yum update && yum install ansible

Image description

Check ansible version

ansible --version

We will install Jenkins using Ansible playbook.

cat > setup_jenkins.yml<< EOF 
---
- hosts: localhost
  connection: local
  vars:
    java_packages:
      - java-17-amazon-corretto-devel
    jenkins_packages:
      - jenkins  
  tasks:
    - name: Download Jenkins repository file
      get_url:
        url: https://pkg.jenkins.io/redhat-stable/jenkins.repo
        dest: /etc/yum.repos.d/jenkins.repo
      become: true

    - name: Import Jenkins-CI key
      shell: rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io-2023.key
      become: true

    - name: Install Java
      yum:
        name: "{{ java_packages }}"
        state: present
      become: true

    - name: Install Jenkins
      yum:
        name: "{{ jenkins_packages }}"
        state: present
      become: true

    - name: Start Jenkins service
      service:
        name: jenkins
        state: started
      become: true
EOF
Enter fullscreen mode Exit fullscreen mode

Then run:
ansible-playbook setup_jenkins.yml

On success you should be able to see below output

Image description

Now go to your browser at http://:8080/
You should find your password as shown:

Image description

Get the password:
sudo cat /var/lib/jenkins/secrets/initialAdminPassword

Unlock Jenkins: Follow the on-screen instructions to unlock Jenkins and complete the initial setup.
Configure Jenkins: Customize Jenkins settings and install plugins as needed to suit your requirements.

Conclusion
By following these steps, you have successfully configured Jenkins using Ansible on an Amazon Linux 2023 instance. You can now use Jenkins to automate your CI/CD workflows and streamline your development processes.
If you are experiencing an issue contact me on LinkedIn

Top comments (0)