top of page

Install Jenkins on CentOS Using Ansible

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

    - name: Install Java (OpenJDK)
        name: java-11-openjdk
        state: present

    - name: Add Jenkins YUM repository
        name: jenkins
        description: Jenkins
        gpgcheck: yes
        state: present

    - name: Install Jenkins
        name: jenkins
        state: present

    - name: Start Jenkins 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
        var: accesskey.stdout

Here's what each task in the playbook does:

  1. Installs OpenJDK 11, which is required by Jenkins.

  2. Adds the Jenkins YUM repository for CentOS 7, which contains the Jenkins packages.

  3. Installs the Jenkins package.

  4. Starts the Jenkins service and enables it to start at boot.

  5. Retrieves the Jenkins unlock key, which you need for the initial setup.

  6. 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.


Rated 0 out of 5 stars.
No ratings yet

Add a rating
bottom of page