This page shows how to install a Jenkins controller on a RHEL-family server using a Puppet class. The class adds the Jenkins package repository, installs Java and Jenkins, manages the systemd service and installs plugins with the Jenkins CLI. Below the original manifest you will find an explanation of each part, a corrected version that gives the same result on every run, and steps to apply it, check it and fix common errors.
What the example manifest does and where it breaks
The example above is a single Puppet class. It also expects a jenkins.service unit file and some secret files in the module's files/ directory. A source such as puppet:///modules/jenkins/jenkins.service maps to modules/jenkins/files/jenkins.service on the Puppet server. The table lists what each part is meant to do and what goes wrong on a current system.
| Part of the manifest | Intent | Problem |
|---|---|---|
exec with wget ... jenkins.repo | Add the Jenkins yum repository | Runs on every Puppet run, uses sudo even though the agent already runs as root, and disables TLS checks with --no-check-certificate |
exec with rpm --import .../jenkins.io.key | Trust the package signing key | Jenkins replaced that key in 2023, so packages fail the GPG check |
java-11-openjdk-demo.x86_64 | Install Java | This is the OpenJDK demo package, not a Java runtime. Current Jenkins releases no longer support Java 11 |
file replacing /usr/lib/systemd/system/jenkins.service | Customise the service | Overwrites a file the package owns. The daemon-reload notify is commented out, so systemd may keep using the old unit |
JAVA_OPTS=-Djava.awt.headless=true, -D... | Pass JVM options | The comma becomes part of the first property's value (true,). JVM options must be separated by spaces |
file for master.key and initialAdminPassword | Seed secrets | The parent directory /var/lib/jenkins/secrets does not exist until Jenkins first starts, and mode 0644 lets every local user read the keys |
exec with wget .../jenkins-cli.jar -P | Fetch the CLI | Runs before Jenkins is ready. On later runs it saves extra copies such as jenkins-cli.jar.1 |
Plugin exec with creates => "...${plugin}*.jpi" | Install plugins once | creates does not expand wildcards, so the command runs every time. Plugins also stay inactive until Jenkins restarts |
Prerequisites
- A RHEL, Rocky Linux, AlmaLinux or CentOS Stream 8/9 host with outbound HTTPS access to
pkg.jenkins.ioandupdates.jenkins.io. - Puppet agent installed (commands below use
/opt/puppetlabs/bin/puppet). Eitherpuppet applyon the host or a Puppet server will work. - A Java runtime that your Jenkins version supports. Java 21 (
java-21-openjdk) is the safe default, but check the Jenkins Java support policy for the release you install. - At least 2 GB of RAM and free disk space under
/var/lib/jenkins.
Corrected Puppet manifest
The version below gives the same result on every run: run it twice and the second run makes no changes. The class is renamed to jenkins_server so it cannot clash with the community jenkins module from the Puppet Forge. The original's doc comment also referred to include dof_jenkins, which did not match the class name. Save the file as modules/jenkins_server/manifests/init.pp.
# @summary Installs a Jenkins controller on RHEL-family hosts and adds plugins.
#
# @param plugins Plugin IDs to install with the Jenkins CLI.
# @param java_package OpenJDK package that provides a supported Java runtime.
# @param port HTTP port Jenkins listens on.
# @param cli_auth_file File containing user:password-or-token for the CLI.
#
# @example
# include jenkins_server
class jenkins_server (
Array[String[1]] $plugins = ['msbuild', 'active-directory'],
String[1] $java_package = 'java-21-openjdk',
Integer[1, 65535] $port = 8080,
String[1] $cli_auth_file = '/root/.jenkins-cli-auth',
) {
$jenkins_home = '/var/lib/jenkins'
$cli_jar = "${jenkins_home}/jenkins-cli.jar"
$jenkins_url = "http://localhost:${port}/"
# Repository and signing key, managed natively instead of wget/rpm execs
yumrepo { 'jenkins':
ensure => present,
descr => 'Jenkins-stable',
baseurl => 'https://pkg.jenkins.io/redhat-stable',
enabled => '1',
gpgcheck => '1',
gpgkey => 'https://pkg.jenkins.io/redhat-stable/jenkins.io-2023.key',
}
package { ['fontconfig', $java_package]:
ensure => installed,
}
package { 'jenkins':
ensure => installed,
require => [Yumrepo['jenkins'], Package[$java_package]],
}
# systemd drop-in instead of overwriting the packaged unit file
file { '/etc/systemd/system/jenkins.service.d':
ensure => directory,
owner => 'root',
group => 'root',
mode => '0755',
}
file { '/etc/systemd/system/jenkins.service.d/override.conf':
ensure => file,
owner => 'root',
group => 'root',
mode => '0644',
content => @("CONF"),
[Service]
Environment="JAVA_OPTS=-Djava.awt.headless=true"
Environment="JENKINS_PORT=${port}"
| CONF
require => Package['jenkins'],
notify => Exec['jenkins-daemon-reload'],
}
exec { 'jenkins-daemon-reload':
command => '/usr/bin/systemctl daemon-reload',
refreshonly => true,
notify => Service['jenkins'],
}
service { 'jenkins':
ensure => running,
enable => true,
require => Package['jenkins'],
}
# Download the CLI once; retry while Jenkins is still starting
exec { 'download-jenkins-cli':
command => "/usr/bin/curl -sSf -o ${cli_jar} ${jenkins_url}jnlpJars/jenkins-cli.jar",
creates => $cli_jar,
tries => 30,
try_sleep => 10,
require => Service['jenkins'],
}
# First run only: build CLI credentials from the generated admin password
exec { 'jenkins-cli-auth-bootstrap':
command => "umask 077 && printf 'admin:%s' \"\$(cat ${jenkins_home}/secrets/initialAdminPassword)\" > ${cli_auth_file}",
provider => shell,
path => ['/usr/bin', '/bin'],
creates => $cli_auth_file,
onlyif => "test -s ${jenkins_home}/secrets/initialAdminPassword",
require => Exec['download-jenkins-cli'],
}
# Install every missing plugin in one call, then let Jenkins restart
unless $plugins.empty {
$plugin_args = $plugins.join(' ')
$plugin_checks = $plugins.map |$p| { "test -e ${jenkins_home}/plugins/${p}.jpi" }.join(' && ')
exec { 'jenkins-install-plugins':
command => "java -jar ${cli_jar} -s ${jenkins_url} -auth @${cli_auth_file} install-plugin ${plugin_args} -restart",
provider => shell,
path => ['/usr/bin', '/usr/sbin', '/bin'],
unless => $plugin_checks,
require => [Exec['download-jenkins-cli'], Exec['jenkins-cli-auth-bootstrap']],
}
}
}
yumrepowrites/etc/yum.repos.d/jenkins.repoand sets the key. dnf imports the key fromgpgkeythe first time it installs a package from that repository. Jenkins rotates its signing key from time to time, so check the current key file name on pkg.jenkins.io before you deploy.- The drop-in
override.confsurvives package upgrades. Changing it triggersdaemon-reloadand then a service restart. creates,unlessandonlyifmake eachexecrun only when its work is not yet done. That is why a second run reports no changes.triesandtry_sleepgive Jenkins up to five minutes to start.curl -ffails on the 503 page Jenkins serves while it is starting, so Puppet retries.- One
install-plugin ... -restartcall avoids restarting Jenkins once per plugin. A per-pluginnotify => Service['jenkins']would also create a dependency cycle. provider => shellis required because the commands use&&,$(...)and output redirection.
Note: The setup wizard stays enabled on purpose. Jenkins then creates an admin user and writes its password to /var/lib/jenkins/secrets/initialAdminPassword, which the bootstrap step uses for the CLI. If you add -Djenkins.install.runSetupWizard=false (space-separated, not comma-separated), Jenkins may start with no security at all unless you also set up security, for example with the Configuration as Code plugin.
Apply the manifest
- Create the module directory:
sudo mkdir -p /etc/puppetlabs/code/environments/production/modules/jenkins_server/manifests. - Save the corrected class as
init.ppin that directory. - Check the syntax:
sudo /opt/puppetlabs/bin/puppet parser validate /etc/puppetlabs/code/environments/production/modules/jenkins_server/manifests/init.pp. - Preview the changes without making them:
sudo /opt/puppetlabs/bin/puppet apply --noop -e 'include jenkins_server'. - Apply:
sudo /opt/puppetlabs/bin/puppet apply -e 'include jenkins_server'. On a Puppet server, addinclude jenkins_serverto the node's role or profile class instead. - Run the apply command again. It should finish with
Notice: Applied catalog in ... secondsand show no resource changes.
To change the plugin list without editing code, set the class parameter in Hiera. The plugin ID is the short name shown on the plugin's page on plugins.jenkins.io.
# data/nodes/jenkins01.example.com.yaml
jenkins_server::plugins:
- git
- workflow-aggregator
- active-directory
- msbuild
jenkins_server::port: 8080Code language: PHP (php)
Verify the installation
# Service is enabled and running
systemctl status jenkins --no-pager
# Drop-in is in effect (should list override.conf)
systemctl cat jenkins | grep -A3 override.conf
# HTTP endpoint answers (expect HTTP/1.1 200 or 403)
curl -sI http://localhost:8080/login | head -n 1
# Plugins were installed
sudo java -jar /var/lib/jenkins/jenkins-cli.jar -s http://localhost:8080/ \
-auth @/root/.jenkins-cli-auth list-plugins | grep -E 'msbuild|active-directory'
# Open the port if firewalld is active
sudo firewall-cmd --permanent --add-port=8080/tcp && sudo firewall-cmd --reloadCode language: PHP (php)
Open http://<server>:8080 in a browser and log in as admin with the contents of /var/lib/jenkins/secrets/initialAdminPassword, then finish the setup wizard. If the wizard replaces the admin account with a new user, generate an API token for that user and put user:token in /root/.jenkins-cli-auth. Otherwise later plugin installs will fail with 401.
Common errors and fixes
| Error | Cause | Fix |
|---|---|---|
Could not find class jenkins_server | Module is not in the environment's module path, or the folder name does not match the class name | Place it at modules/jenkins_server/manifests/init.pp and check with puppet config print modulepath |
GPG check FAILED or NOKEY when installing jenkins | An outdated signing key, such as jenkins.io.key, was imported | Point gpgkey at the current key file and remove the old key with rpm -e gpg-pubkey-<id> |
| Jenkins exits with a message about an unsupported Java version | Java 11 or another unsupported runtime is the default java | Install java-21-openjdk and select it with alternatives --config java |
Could not set 'file' on ensure: No such file or directory for master.key | /var/lib/jenkins/secrets does not exist before the first start | Do not manage master.key this way. See the security notes below |
curl: (7) Failed to connect or (22) ... 503 | Jenkins is still starting | Already handled by tries/try_sleep. Increase them on slow hosts and check journalctl -u jenkins |
CLI returns 401 Unauthorized | The auth file does not contain a valid user:password or user:token | Regenerate an API token and rewrite the file with mode 0600 |
Found 1 dependency cycle | A plugin exec notifies the service it depends on | Use install-plugin ... -restart as in the corrected manifest |
Security and production notes
- Never ship
master.keyfrom a module. It decrypts every credential stored in Jenkins. Copying one key to many servers, readable by everyone (mode0644), defeats that protection. Migrate it only with the rest of$JENKINS_HOME/secrets, owned byjenkinswith mode0600. - Keep secrets out of plain manifests. If you manage the CLI auth file from Puppet, pass the token as
Sensitivefrom Hiera eyaml and setmode => '0600'. - Do not disable TLS verification.
--no-check-certificateallows a tampered repository file. Theyumreporesource withgpgcheckenabled avoids this. - Pin versions for production. Replace
ensure => installedwith a specific Jenkins LTS version once you have tested it, so a Puppet run never upgrades Jenkins unexpectedly. - Consider the maintained alternatives. The community
puppet/jenkinsForge module manages the repository, package, service and plugins. Jenkins Configuration as Code (JCasC) andjenkins-plugin-clihandle security, settings and plugin versions more reliably than CLI calls fromexec.
Frequently asked questions
How do I install Jenkins plugins with Puppet?
Download jenkins-cli.jar from http://localhost:8080/jnlpJars/jenkins-cli.jar. Then run java -jar jenkins-cli.jar -s http://localhost:8080/ -auth @authfile install-plugin <ids> -restart from an exec, with an unless check on /var/lib/jenkins/plugins/<id>.jpi. The puppet/jenkins Forge module or Configuration as Code are more robust options for larger setups.
Why does Puppet run my Jenkins exec resources on every run?
An exec without creates, unless, onlyif or refreshonly runs every time. creates also checks a literal path and does not expand wildcards such as *.jpi.
Which Java version does Jenkins need?
Current Jenkins releases no longer support Java 11. Use a supported release such as Java 21, and check the Jenkins Java support policy for the exact versions your Jenkins release accepts.
Where is the Jenkins initial admin password?
With the setup wizard enabled, Jenkins writes it to /var/lib/jenkins/secrets/initialAdminPassword on first start. The file is removed once the wizard is completed.
Should I edit /usr/lib/systemd/system/jenkins.service?
No. That file belongs to the package and is replaced on upgrade. Put overrides in /etc/systemd/system/jenkins.service.d/override.conf (or use systemctl edit jenkins) and run systemctl daemon-reload.
Related tutorials
- More Puppet tutorials
- More Jenkins tutorials
- What is Puppet and use cases of Puppet?
- What is Jenkins and use cases of Jenkins?
I’m Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms.
I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.
Find Trusted Cardiac Hospitals
Compare heart hospitals by city and services โ all in one place.
Explore Hospitals