使用Packer+VirtualBox+Vagrant模板安装Puppet5 Agent异常咨询
Let’s walk through why your Puppet Agent 5 isn’t showing up despite Packer logs claiming the build completed, and how to fix this stubborn issue:
1. Double-Check Your Puppet Repository Setup
Ubuntu 16.04 ships with Puppet 3.x in its default system repositories. If your Packer provisioning script doesn’t explicitly add the Puppet 5 repo, apt will automatically pull the outdated 3.8.x version instead. Verify your provisioner includes these steps:
# Correct repo setup for Puppet 5 on Ubuntu 16.04 (Xenial) wget https://apt.puppetlabs.com/puppet5-release-xenial.deb dpkg -i puppet5-release-xenial.deb apt-get update -y
Using the wrong release file (e.g., for a newer Ubuntu version) or skipping this repo setup entirely is the most common culprit here.
2. Confirm the Puppet Agent Install Command Ran Successfully
Packer logs might say "operation completed" even if the install command failed silently (e.g., network timeouts during repo updates, unmet dependencies). Add verbose output to your install command to catch hidden errors:
apt-get install -y puppet-agent -o Debug::pkgProblemResolver=yes
Also, comb through the full Packer build logs again—sometimes "completed" just means the script finished running, not that every command executed successfully. Look for lines like E: Unable to locate package puppet-agent or dependency conflicts.
3. Make Sure You’re Installing the Right Package
It’s an easy typo to make: Puppet 5’s agent package is puppet-agent, not the older puppet package (which installs Puppet 3.x and pulls in puppet-common as a dependency). Double-check your provisioning script uses:
apt-get install -y puppet-agent
If you used apt-get install puppet instead, that’s exactly why you’re seeing the old version.
4. Force a Clean Packer Build
Even if you deleted the old Vagrant box, Packer might reuse cached intermediate artifacts (like the base Ubuntu image or partial provisioning outputs). Run a fully clean build with:
PACKER_LOG=1 packer build -force ubuntu-16.04.json
The -force flag tells Packer to discard all cached data and start from scratch.
5. Check Provisioner Step Order
If you have cleanup steps (e.g., removing unused packages, purging repo files) that run after installing Puppet Agent, they might be wiping out the agent or its repo configuration. Ensure your provisioning flow follows this order:
- Add Puppet 5 repository
- Update apt cache
- Install
puppet-agent - Run system cleanup (avoid commands that remove Puppet packages or repo files)
6. Test Manually in a Raw VM
To rule out Packer-specific quirks, spin up a fresh Ubuntu 16.04 VM directly in VirtualBox (no Packer involved) and run your provisioning commands one by one. If the agent installs correctly here, the issue lies in your Packer configuration; if it fails, you’ll get direct error messages to debug.
内容的提问来源于stack exchange,提问作者Max

