puppetlabs/puppet · error · Puppet::Error

Could not find package %{name}

Error message

Could not find package %{name}

What it means

The aptitude provider's aptget helper (aptitude.rb:22) raises Puppet::Error when an install command's output matches /Couldn't find any package/. This is a workaround for aptitude exiting 0 (success) even when the requested package does not exist in any configured repository, so Puppet scans stdout to convert that silent no-op into a real failure.

Source

Thrown at lib/puppet/provider/package/aptitude.rb:22

  desc "Package management via `aptitude`."

  has_feature :versionable

  commands :aptitude => "/usr/bin/aptitude"
  commands :aptcache => "/usr/bin/apt-cache"

  ENV['DEBIAN_FRONTEND'] = "noninteractive"

  def aptget(*args)
    args.flatten!
    # Apparently aptitude hasn't always supported a -q flag.
    args.delete("-q") if args.include?("-q")
    args.delete("--force-yes") if args.include?("--force-yes")
    output = aptitude(*args)

    # Yay, stupid aptitude doesn't throw an error when the package is missing.
    if args.include?(:install) and output.to_s =~ /Couldn't find any package/
      raise Puppet::Error, _("Could not find package %{name}") % { name: name }
    end
  end

  def purge
    aptitude '-y', 'purge', @resource[:name]
  end

  private

  def source
    nil
  end
end

View on GitHub (pinned to e227c27540)

Solutions

  1. Confirm the package exists: `aptitude search '^<name>$'` on the node.
  2. Run `aptitude update` (or manage an apt::source + exec refresh) so package lists are populated before the package resource.
  3. Fix the resource name spelling; if the package lives in another component/repo, declare that repo in Puppet first (before => Package[...]).

Example fix

# before
package { 'pyhton3-pip': ensure => installed, provider => aptitude }

# after
exec { 'aptitude-update': command => '/usr/bin/aptitude update', before => Package['python3-pip'], refreshonly => true }
package { 'python3-pip': ensure => installed, provider => aptitude }
Defensive patterns

Strategy: validation

Validate before calling

# verify the package exists before installing
system("aptitude search '^foo$' | grep -q '^i\\|^p  foo'") or raise 'package foo not in any repo'
# and ensure lists are fresh
system('aptitude update') or raise 'aptitude update failed'

Try / catch

begin
  aptitude_provider.aptget(:install, 'foo')
rescue Puppet::Error => e
  raise unless e.message =~ /Could not find package/
  # refresh indexes once and retry
  system('aptitude update'); retry
end

Prevention

When it happens

Trigger: package { X: ensure => installed, provider => aptitude } where X is misspelled, not present in any enabled apt repo, or the apt lists are stale/empty (apt-get update never ran, repo key expired so lists were discarded).

Common situations: Typo'd package names in shared modules; fresh nodes where `aptitude update` has not run; third-party repos whose signing keys expired so their package lists are gone; suite renamed (oldstable packages removed upstream).

Related errors


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