MYHOSPITALNOW.COM

Find Trusted Doctors & Hospitals

Discover healthcare providers, compare hospitals, and explore treatment options worldwide.

Free Treatment Quotes • Doctor Search • Hospital Comparison

Find Healthcare Options

www.myhospitalnow.com

Puppet: Jenkins Installation using Puppet Program

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 manifestIntentProblem
exec with wget ... jenkins.repoAdd the Jenkins yum repositoryRuns 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.keyTrust the package signing keyJenkins replaced that key in 2023, so packages fail the GPG check
java-11-openjdk-demo.x86_64Install JavaThis is the OpenJDK demo package, not a Java runtime. Current Jenkins releases no longer support Java 11
file replacing /usr/lib/systemd/system/jenkins.serviceCustomise the serviceOverwrites 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 optionsThe comma becomes part of the first property's value (true,). JVM options must be separated by spaces
file for master.key and initialAdminPasswordSeed secretsThe 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 -PFetch the CLIRuns 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 oncecreates 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.io and updates.jenkins.io.
  • Puppet agent installed (commands below use /opt/puppetlabs/bin/puppet). Either puppet apply on 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']],
    }
  }
}
  • yumrepo writes /etc/yum.repos.d/jenkins.repo and sets the key. dnf imports the key from gpgkey the 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.conf survives package upgrades. Changing it triggers daemon-reload and then a service restart.
  • creates, unless and onlyif make each exec run only when its work is not yet done. That is why a second run reports no changes.
  • tries and try_sleep give Jenkins up to five minutes to start. curl -f fails on the 503 page Jenkins serves while it is starting, so Puppet retries.
  • One install-plugin ... -restart call avoids restarting Jenkins once per plugin. A per-plugin notify => Service['jenkins'] would also create a dependency cycle.
  • provider => shell is 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

  1. Create the module directory: sudo mkdir -p /etc/puppetlabs/code/environments/production/modules/jenkins_server/manifests.
  2. Save the corrected class as init.pp in that directory.
  3. Check the syntax: sudo /opt/puppetlabs/bin/puppet parser validate /etc/puppetlabs/code/environments/production/modules/jenkins_server/manifests/init.pp.
  4. Preview the changes without making them: sudo /opt/puppetlabs/bin/puppet apply --noop -e 'include jenkins_server'.
  5. Apply: sudo /opt/puppetlabs/bin/puppet apply -e 'include jenkins_server'. On a Puppet server, add include jenkins_server to the node's role or profile class instead.
  6. Run the apply command again. It should finish with Notice: Applied catalog in ... seconds and 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

ErrorCauseFix
Could not find class jenkins_serverModule is not in the environment's module path, or the folder name does not match the class namePlace it at modules/jenkins_server/manifests/init.pp and check with puppet config print modulepath
GPG check FAILED or NOKEY when installing jenkinsAn outdated signing key, such as jenkins.io.key, was importedPoint 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 versionJava 11 or another unsupported runtime is the default javaInstall 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 startDo not manage master.key this way. See the security notes below
curl: (7) Failed to connect or (22) ... 503Jenkins is still startingAlready handled by tries/try_sleep. Increase them on slow hosts and check journalctl -u jenkins
CLI returns 401 UnauthorizedThe auth file does not contain a valid user:password or user:tokenRegenerate an API token and rewrite the file with mode 0600
Found 1 dependency cycleA plugin exec notifies the service it depends onUse install-plugin ... -restart as in the corrected manifest

Security and production notes

  • Never ship master.key from a module. It decrypts every credential stored in Jenkins. Copying one key to many servers, readable by everyone (mode 0644), defeats that protection. Migrate it only with the rest of $JENKINS_HOME/secrets, owned by jenkins with mode 0600.
  • Keep secrets out of plain manifests. If you manage the CLI auth file from Puppet, pass the token as Sensitive from Hiera eyaml and set mode => '0600'.
  • Do not disable TLS verification. --no-check-certificate allows a tampered repository file. The yumrepo resource with gpgcheck enabled avoids this.
  • Pin versions for production. Replace ensure => installed with 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/jenkins Forge module manages the repository, package, service and plugins. Jenkins Configuration as Code (JCasC) and jenkins-plugin-cli handle security, settings and plugin versions more reliably than CLI calls from exec.

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

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services โ€” all in one place.

Explore Hospitals
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.

Related Posts

Puppet Training Agenda: A Practical Roadmap from Basics to Real-World Automation

This revised guide converts the original Puppet course outline into a clear learning path for DevOps and platform teams. It covers architecture, run cycle, hands-on manifests, ecosystem tools, and common implementation pitfalls.

Read More

Puppet Training Roadmap for DevOps and System Administrators

This revised guide turns the original Puppet course post into a practical training roadmap for DevOps and sysadmin teams. It covers what to learn, how Puppet runs work, key commands to practice, and how to structure a 1-day or 2-day workshop.

Read More

Master DevOps Automation with Puppet Training in Bangalore

Introduction In todayโ€™s fast-moving tech world, companies need to manage their computer systems quickly and without mistakes. Puppet is a powerful tool that helps do just this….

Read More

What is Puppet and use cases of Puppet?

What is Puppet? Puppet is an open-source configuration management and automation tool that helps IT operations teams automate the provisioning, configuration, and management of infrastructure and applications….

Read More

Puppet Assignment and Excercise

Rajesh Kumar 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…

Read More

Complete Puppet Certification Guide & tutorials

What is Puppet? Puppet is an open source configuration management and deployment tool that automate the configuration of servers. When you use Puppet, you define the desired…

Read More
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
0
Would love your thoughts, please comment.x
()
x