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
    end

View on GitHub (pinned to e227c27540)

Solutions

  1. 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.
  2. Set the resource `name` explicitly if the title must stay descriptive: `package { 'label': name => 'real-pkg-name', ... }`.
  3. 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

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


AI-assisted analysis of puppetlabs/puppet@e227c27540 (2026-08-21). Data as JSON: /api/errors/a93ab9280bbe7072. Report an issue: GitHub.