To install Jenkins on CentOS using Ansible, you can use the following playbook. Ensure you have Ansible installed and configured to connect to your target CentOS server.
---
- name: Install Jenkins on CentOS 7
hosts: jenkinshost
become: yes
tasks:
- name: Install Java (OpenJDK)
yum:
name: java-11-openjdk
state: present
- name: Add Jenkins YUM repository
yum_repository:
name: jenkins
description: Jenkins
baseurl: http://pkg.jenkins.io/redhat-stable
gpgcheck: yes
gpgkey: https://pkg.jenkins.io/redhat-stable/jenkins.io-2023.key
state: present
- name: Install Jenkins
yum:
name: jenkins
state: present
- name: Start Jenkins service
service:
name: jenkins
state: started
enabled: yes
- name: Get Jenkins unlock key
command: cat /var/lib/jenkins/secrets/initialAdminPassword
register: accesskey
- name: Display Jenkins unlock key
debug:
var: accesskey.stdout
Here's what each task in the playbook does:
Installs OpenJDK 11, which is required by Jenkins.
Adds the Jenkins YUM repository for CentOS 7, which contains the Jenkins packages.
Installs the Jenkins package.
Starts the Jenkins service and enables it to start at boot.
Retrieves the Jenkins unlock key, which you need for the initial setup.
Displays the unlock key to the console so you can use it to complete the Jenkins setup through the web interface.
Here's the output of the above playbook
Now, let's try to browse the Jenkins URL over port 8080.
As you can see here we are able to access Jenkins via browser using the server's IP address and port 8080. You'll need to enter the unlock key to set up Jenkins.
Comments