Puppet Troubleshooting: Debug Runs, Read Errors, Fix Common Problems Step by Step
A Method That Works
- Read the first error, not the last. Later errors are often caused by it
- Decide where it failed: compile (on server) or apply (on agent)
- Reproduce it in the smallest way:
puppet apply -e '...' or one node with --noop
- Add detail:
--debug, --trace, puppet lookup --explain
- Fix one thing, rerun, confirm. Then add a test so it cannot return
Compile Error or Apply Error?
| Message starts with | Where | Typical causes |
Error: Could not retrieve catalog from remote server | Compile on the server | Syntax, missing class, bad Hiera data, duplicate declaration, missing parameter |
Error: Evaluation Error: ... | Compile | Wrong type, undefined variable, function error |
Error: Failed to apply catalog | Apply on agent | Dependency cycle, other catalog problems |
Error: /Stage[main]/.../Package[x]/ensure: change from absent to present failed | Apply | A resource failed: package not found, service will not start, file permission |
Warning: ... Skipping because of failed dependencies | Apply | A required resource failed earlier. Fix the earlier one |
Run with More Detail
bash
sudo puppet agent -t # normal, verbose
sudo puppet agent -t --noop # what would change
sudo puppet agent -t --debug 2>&1 | tee /tmp/puppet-debug.log
sudo puppet agent -t --trace # include Ruby stack traces for internal errors
sudo puppet agent -t --evaltrace # list every resource with timing
sudo puppet agent -t --summarize # statistics at the end
sudo puppet agent -t --tags nginx # only part of the catalog
sudo puppet apply --debug --noop site.pp
puppet config print --section agent
The Server Side
bash
sudo tail -f /var/log/puppetlabs/puppetserver/puppetserver.log
sudo journalctl -u puppetserver -f
sudo grep -i 'error' /var/log/puppetlabs/puppetserver/puppetserver.log | tail -20
# Compile a catalog on the server for one node and read the errors
sudo puppet catalog compile web01.example.com --environment production | head
# Raise server log level temporarily (logback.xml: <root level="debug">) and reload
sudo systemctl reload puppetserver
Common Errors and Fixes
| Error message (shortened) | Cause | Fix |
Syntax error at '}' / Could not parse for environment | Missing comma, brace or quote | puppet parser validate file.pp. Look just above the reported line |
Evaluation Error: Unknown variable: 'foo' | Variable not defined in scope, or a fact missing | Define it, check spelling, use $facts['x'] and dig, or set strict variables on purpose |
Could not find class ::profile::nginx | Wrong name, wrong file path, module not deployed | Check manifests/nginx.pp, puppet module list --modulepath, r10k run |
Duplicate declaration: Package[git] is already declared | Two classes declare the same resource | Use ensure_packages(['git']), or declare it in one place |
Duplicate declaration: Class[X] is already declared | class { 'X': } used twice | Use include and Hiera instead of resource-like declarations |
Evaluation Error: Error while evaluating a Resource Statement, Class[X]: expects a value for parameter 'y' | Required parameter has no value | Add a default or Hiera data (X::y) |
parameter 'port' expects an Integer value, got String | Type mismatch (often from YAML quotes) | Fix the data (8080 not '8080') or the type |
Found 1 dependency cycle | Resources depend on each other | Remove one relationship. Draw with --graph |
Could not find resource 'Service[nginx]' for relationship | Relationship target is not in catalog | Declare it or include the class that does |
Evaluation Error: Unknown function: 'foo' | Missing module or older version | Add module to Puppetfile and deploy |
Could not evaluate: Execution of '/usr/bin/dnf -d 0 -e 1 -y install foo' returned 1 | Package not found / repo problem | Run the command by hand, add repo, fix the name |
Could not enable/start service | Config error or port in use | systemctl status, journalctl -xe, test config |
Cannot alias File[/x] to [...]; resource already declared | Same path declared twice with different titles | Use one resource per path |
Failed to parse template ... | EPP/ERB syntax or missing variable | puppet epp validate, check parameters passed |
Could not autoload ... | Class in wrong file, bad Ruby in lib | Fix naming, ruby -c the file |
Server Error: Failed when searching for node ... | ENC or classification error | Test the ENC script by hand |
Error: Could not find data item 'x' in any Hiera data file and no default supplied | Missing data | Add to Hiera or give a default value, use puppet lookup --explain |
Find Which File Causes the Problem
bash
puppet lookup profile::nginx::port --node web01.example.com --explain
puppet apply --noop --modulepath ./modules -e 'include profile::nginx'
puppet resource package nginx
puppet describe file | less # check attribute names and allowed values
puppet module list --tree
puppet config print modulepath environmentpath
Problem: Resources Change on Every Run
If the report shows the same resource changing each run, the code is not idempotent. This causes noise, risk and wasted time.
| Pattern | Why it happens | Fix |
exec with no guard | Runs every time | Add creates, unless, onlyif, or refreshonly |
| File content has a timestamp or random value | Content differs each run | Remove dynamic parts or generate once |
mode => 644 (number) or 0644 unquoted | Puppet parses differently | Quote: '0644' |
package with ensure => latest | Upgrades whenever a new version appears | Pin a version or use installed |
| Service starts but status check fails | Wrong status or hasstatus | Set a status command |
user password hash differs between OS | Different hash format | Use a correct hash for the OS |
| Resource managed in two places | Each class sets a different value | One owner per resource |
bash
# Find resources that change on the second run
sudo puppet agent -t # first run
sudo puppet agent -t # second run: look for lines starting with "Notice: /Stage[main]..."
sudo puppet agent -t --show_diff | head -40 # see what changed in files
Problem: Agent Cannot Contact Server
bash
c -zv puppet.example.com 8140
curl -sk https://puppet.example.com:8140/status/v1/simple
openssl s_client -connect puppet.example.com:8140 -servername puppet.example.com </dev/null 2>/dev/null | openssl x509 -noout -subject -issuer -dates
date; chronyc tracking # clock must be right
puppet config print server certname ssldir
Look back at the certificate lesson for the SSL fixes. Time difference, wrong server name and old certificates are the three most common reasons.
Problem: Slow Runs
bash
sudo puppet agent -t --evaltrace --summarize 2>&1 | tail -30
cat /opt/puppetlabs/puppet/public/last_run_summary.yaml | grep -A12 '^time'
facter --timing 2>&1 | sort -t: -k2 -n | tail # which fact is slow? (use --timing in your Facter version)
| Slow part | Cause | Fix |
config_retrieval | Catalog compile is slow or facts are slow | Server resources, slow facts, huge Hiera data |
package | Package manager is slow | Local mirror, avoid latest |
Many file resources | Large directory with recurse => true | Use a package or archive, use checksum => mtime |
exec | Long commands, timeout | Run once with creates, move to Bolt |
Problem: Agent Run Is Locked or Disabled
bash
# Error: Skipping run of Puppet configuration client; administratively disabled (Reason: 'maintenance')
sudo puppet agent --enable
# Error: Run of Puppet configuration client already in progress
ps aux | grep '[p]uppet agent'
sudo rm -f /opt/puppetlabs/puppet/cache/state/agent_catalog_run.lock # ONLY if no puppet process is running
Isolate With a Tiny Test
bash
# Put the failing resource in a file and run it alone
cat > /tmp/t.pp <<'EOF'
file { '/tmp/demo.conf':
ensure => file,
content => epp('profile/demo.conf.epp', { 'port' => 8080 }),
}
EOF
sudo puppet apply --modulepath ./site-modules:./modules /tmp/t.pp --debug --noop
Useful Debug Techniques in Code
puppet
otice("DEBUG port = ${port}, type = ${type($port)}")
notice(inline_epp('<%= $facts["os"]["family"] %>'))
$data = lookup('profile::nginx::vhosts', Hash, 'deep', {})
notice(stdlib::to_json_pretty($data)) # view a structure clearly (stdlib)
# Stop here to inspect
# fail("STOP: reached this line")
When to Ask for Help
- Include: Puppet version, OS, the exact error text, a minimal example that fails
- Search the error text in the module's issues and the community Slack or forum
- Check the module's changelog for breaking changes
- For OpenVox or Puppet differences, look at the project's release notes and issue tracker
Practice Tasks
- Cause a duplicate declaration on purpose and fix it with
ensure_packages
- Create a dependency cycle and read the error
- Create a non-idempotent
exec, spot it in the second run, and fix it with creates
- Misspell a Hiera key and find it with
puppet lookup --explain
- Read
puppetserver.log while an agent hits a compile error
Conclusion
Troubleshoot by locating the stage (compile or apply), reading the first error, reproducing in a small test, and using --debug, puppet lookup --explain and server logs. Fix non-idempotent resources, and add tests to prevent regressions.
Quick Summary: first error; compile vs apply; --debug/--trace/--evaltrace; duplicate declaration; cycles; idempotence; lock files.