Puppet Forge Modules in Practice: Puppetfile, r10k, Versions and Dependencies

Puppet Training Course 22 min min read Updated: Nov 17, 2026 Intermediate
Puppet Forge Modules in Practice: Puppetfile, r10k, Versions and Dependencies
Intermediate Topic 2 of 4

Why Not Install Modules by Hand?

If you run puppet module install on one server, other servers do not know about it, and nobody knows which version is used. In real teams, everything is in Git: your own code, the list of modules and their versions. Then each environment (production, staging) is just a Git branch.

The Control Repository

A control repo is one Git repository that describes a whole Puppet environment.

text control-repo/ Puppetfile list of modules and versions (Forge and Git) environment.conf environment settings (modulepath) hiera.yaml environment-level Hiera 5 configuration data/ Hiera data for this environment common.yaml nodes/web01.example.com.yaml role/webserver.yaml manifests/ site.pp node classification (entry point) site-modules/ your own modules: role, profile, ... role/manifests/webserver.pp profile/manifests/nginx.pp .fixtures.yml, Rakefile, spec/ tests
ini # environment.conf modulepath = site-modules:modules:$basemodulepath

Modules in site-modules/ are your own. Modules in modules/ are downloaded by r10k from the Puppetfile, so modules/ should be in .gitignore.

The Puppetfile

ruby # Puppetfile forge 'https://forge.puppet.com' # Forge modules with exact versions mod 'puppetlabs-stdlib', '9.6.0' mod 'puppetlabs-concat', '9.0.2' mod 'puppetlabs-apt', '9.4.0' mod 'puppet-nginx', '6.0.1' mod 'puppet-archive', '7.1.0' # A module from Git, pinned to a tag mod 'monitoring', git: 'https://github.com/myorg/puppet-monitoring.git', tag: 'v1.4.0' # A module from Git, pinned to a commit (most reproducible) mod 'hardening', git: 'https://github.com/myorg/puppet-hardening.git', ref: '4f1c2ab9d0e3b6c7a8f5e1d2c3b4a5968778695a' # A module from Git following a branch (not for production) mod 'experimental', git: 'https://github.com/myorg/puppet-experimental.git', branch: 'main'
Exact versions: Pin exact versions in the Puppetfile, as in '9.6.0'. Then every server and every test run uses the same code. Update them on purpose, in a pull request.

Install and Use r10k

bash # On a Puppet server (Puppet Server bundles it as Code Manager in PE; for open source install the gem) sudo /opt/puppetlabs/puppet/bin/gem install r10k # /etc/puppetlabs/r10k/r10k.yaml sudo mkdir -p /etc/puppetlabs/r10k sudo tee /etc/puppetlabs/r10k/r10k.yaml <<'EOF' --- cachedir: '/var/cache/r10k' sources: main: remote: 'https://git.example.com/puppet/control-repo.git' basedir: '/etc/puppetlabs/code/environments' EOF sudo /opt/puppetlabs/puppet/bin/r10k deploy environment -p # all branches, install modules sudo /opt/puppetlabs/puppet/bin/r10k deploy environment production -p -v sudo /opt/puppetlabs/puppet/bin/r10k deploy module stdlib -e production sudo /opt/puppetlabs/puppet/bin/r10k puppetfile check # syntax check ls /etc/puppetlabs/code/environments
CommandWhat it does
r10k deploy environmentCreates or updates environments from Git branches
-p or --puppetfileAlso install modules from each Puppetfile
r10k deploy module NAMEUpdate one module only
r10k puppetfile installInstall modules for a Puppetfile in the current directory (good for local testing)
r10k puppetfile checkSyntax check
r10k deploy displayShow what exists

Branches Are Environments

bash git checkout -b feature_new_ntp # edit Puppetfile and manifests, commit, push git push origin feature_new_ntp sudo r10k deploy environment feature_new_ntp -p sudo puppet agent -t --environment feature_new_ntp --noop # test on a node, nothing changes # if good: merge to production, r10k deploys it sudo puppet agent -t --noop

Branch names become environment names, so use only letters, numbers and underscores (feature_new_ntp, not feature/new-ntp). Many teams automate r10k deploy with a webhook from GitLab or GitHub, or run it in the CI pipeline.

Code Manager (Puppet Enterprise)

Code Manager is the built-in and automated version of r10k in Puppet Enterprise. It reads the same control repo and Puppetfile, deploys to the compilers and gives you the puppet-code deploy command. If you know r10k, you know Code Manager.

bash puppet-code deploy production --wait puppet-code deploy --all --wait

Dependencies and Conflicts

Forge modules declare dependencies in metadata.json, but r10k does not resolve them. You must list every module and its dependencies in the Puppetfile yourself, with versions that agree.

ProblemHow to handle
Module A needs stdlib < 9, module B needs >= 9Check each module's metadata.json, pick versions that agree, or update the module
Missing dependency error at compile timeCould not find class: add the missing module to the Puppetfile
A tool that resolves dependencieslibrarian-puppet (older), or the puppet module install command for exploring
Many modules, fear of upgradesUpdate a few at a time, run unit tests and --noop before production

Safe Module Update Workflow

  1. Read the module changelog for breaking changes
  2. Create a branch and update the version in the Puppetfile
  3. Run lint and unit tests in CI
  4. Deploy the branch as an environment and run puppet agent -t --noop --environment branch on test nodes
  5. Fix the differences, then run a real apply on a test node
  6. Merge to production and roll out in waves (canary servers first)

Local Testing Without a Server

bash cd control-repo r10k puppetfile install --moduledir modules # downloads all modules locally puppet apply --modulepath site-modules:modules \ -e 'include role::webserver' --noop --hiera_config=hiera.yaml

Best Practices

  • Pin exact versions or commit hashes
  • Keep site-modules (your code) separate from modules (downloaded code)
  • Do not edit downloaded modules in place. Fork them, or set parameters and override with Hiera
  • Use the same Puppetfile in all tests and production, differences go into Hiera data
  • Cache the Forge and Git in a local mirror for speed and availability
  • Review Puppetfile changes in pull requests like any other code

Practice Tasks

  1. Create a control repo with a Puppetfile containing stdlib and concat
  2. Use r10k puppetfile install locally and list modules/
  3. Create a branch, add a module, deploy it as an environment with r10k, and run an agent with --environment
  4. Pin one module to a Git tag and another to a commit
  5. Create an intentional conflict between two modules versions and find the cause

Conclusion

Treat modules like dependencies: list them with exact versions in a Puppetfile, keep your control repository in Git, and let r10k or Code Manager deploy branches as environments.

Quick Summary: control repo; Puppetfile pinned; r10k deploy environment -p; branch = environment; resolve deps yourself.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators