puppetlabs/puppet · error · Puppet::Error
Could not find package %{name}
Error message
Could not find package %{name} What it means
apt.rb:178: when a package was installed with an explicit `source` file and an ensure that is not :present/:installed, the provider re-queries dpkg afterwards to confirm the install. If query returns nil (dpkg-query cannot find the package at all), it raises 'Could not find package %{name}'. This means the .deb staged via source installed something whose dpkg name differs from the resource title/name — or the install silently did nothing.
Source
Thrown at lib/puppet/provider/package/apt.rb:178
# rubocop:disable Style/RedundantCondition
if source
cmd << source
else
cmd << str
end
# rubocop:enable Style/RedundantCondition
unhold if properties[:mark] == :hold
begin
aptget(*cmd)
ensure
hold if @resource[:mark] == :hold
end
# If a source file was specified, we must make sure the expected version was installed from specified file
if source && !%i[present installed].include?(should)
is = query
raise Puppet::Error, _("Could not find package %{name}") % { name: name } unless is
version = is[:ensure]
raise Puppet::Error, _("Failed to update to version %{should}, got version %{version} instead") % { should: should, version: version } unless
insync?(version)
end
end
# What's the latest package version available?
def latest
output = aptcache :policy, @resource[:name]
if output =~ /Candidate:\s+(\S+)\s/
Regexp.last_match(1)
else
err _("Could not find latest version")
nil
endView on GitHub (pinned to e227c27540)
Solutions
- Check the real package name inside the artifact: `dpkg-deb -I /path/to.deb` (or `dpkg-deb -f /path/to.deb Package`) and make the resource name match it exactly.
- Set the resource `name` explicitly if the title must stay descriptive: `package { 'label': name => 'real-pkg-name', ... }`.
- Verify the staged file is a valid deb (file(1), dpkg-deb --info) and that it was actually installed (dpkg -l).
Example fix
# before
package { 'riak': ensure => '2.2.5', source => '/tmp/riak.deb' } # deb actually ships 'riak-2'
# after
package { 'riak': name => 'riak-2', ensure => '2.2.5', source => '/tmp/riak.deb' } Defensive patterns
Strategy: validation
Validate before calling
# confirm name/version in the artifact before puppet applies
pkg = `dpkg-deb -f /tmp/foo.deb Package`.strip
fail "resource name must be #{pkg}" unless pkg == 'foo' Try / catch
begin apt_provider.install rescue Puppet::Error => e raise unless e.message =~ /Could not find package/ # artifact/name mismatch: inspect dpkg-deb -I output, fix resource name, re-run Puppet.err(e.message); raise end
Prevention
- Always cross-check the deb's Package field (dpkg-deb -f <deb> Package) against the resource name in CI.
- Use `name =>` explicitly when titles are descriptive.
- Fail loudly at build time if staged artifacts are not valid debs (file(1) check).
When it happens
Trigger: package resource with both `source => '/path/or/url/to.deb'` and `ensure => '1.2.3'` (a concrete version), where the Package: field inside the .deb does not equal the resource name (e.g. resource title 'foo' but the deb ships package 'foo-tools'), or the deb file is corrupt so dpkg never registered it.
Common situations: Using the resource title as a descriptive label instead of the real package name; renaming debs upstream; versioned deb artifacts where the name changes between versions (daemon vs -bin packages); a source URL that returned an HTML error page instead of a deb.
Related errors
- /etc/apt/sources.list contains a cdrom source; not installin
- Failed to update to version %{should}, got version %{version
- Could not find package %{name}
- You cannot install dpkg packages without a source
- Package #{hash[:name]}, version #{hash[:ensure]} is in error
AI-assisted analysis of puppetlabs/puppet@e227c27540 (2026-08-21).
Data as JSON: /api/errors/a93ab9280bbe7072.
Report an issue: GitHub.