puppetlabs/puppet · error · Puppet::Error

Failed to list packages

Error message

Failed to list packages

What it means

The rpm provider's self.instances shells out to 'rpm -qa --qf ... | sort' via execpipe and wraps any Puppet::ExecutionFailure as Puppet::Error 'Failed to list packages'. It fires during prefetch - any puppet run or 'puppet resource package' on an rpm-based host - when the rpm query itself fails, most commonly a corrupted rpm database in /var/lib/rpm.

Source

Thrown at lib/puppet/provider/package/rpm.rb:75

    '--nosignature' unless Puppet::Util::Package.versioncmp(current_version, '4.1') < 0
  end

  # rpm < 4.0.2 does not support --nodigest
  def self.nodigest
    '--nodigest' unless Puppet::Util::Package.versioncmp(current_version, '4.0.2') < 0
  end

  def self.instances
    packages = []

    # list out all of the packages
    begin
      execpipe("#{command(:rpm)} -qa #{nosignature} #{nodigest} --qf '#{self::NEVRA_FORMAT}' | sort") { |process|
        # now turn each returned line into a package object
        nevra_to_multiversion_hash(process).each { |hash| packages << new(hash) }
      }
    rescue Puppet::ExecutionFailure => e
      raise Puppet::Error, _("Failed to list packages"), e.backtrace
    end

    packages
  end

  # Find the fully versioned package name and the version alone. Returns
  # a hash with entries :instance => fully versioned package name, and
  # :ensure => version-release
  def query
    # NOTE: Prior to a fix for issue 1243, this method potentially returned a cached value
    # IF YOU CALL THIS METHOD, IT WILL CALL RPM
    # Use get(:property) to check if cached values are available
    cmd = ["-q", @resource[:name], self.class.nosignature.to_s, self.class.nodigest.to_s, "--qf", self.class::NEVRA_FORMAT.to_s]

    begin
      output = rpm(*cmd)
    rescue Puppet::ExecutionFailure
      return nil unless @resource.allow_virtual?

View on GitHub (pinned to e227c27540)

Solutions

  1. Reproduce as root: 'rpm -qa' - expect errors like 'db5 error(-30969) from dbenv->open'
  2. Rebuild the rpm database: 'rm -f /var/lib/rpm/__db.*; rpm --rebuilddb'
  3. Free disk/inode space on /var and /tmp if full, then retry the agent run
  4. For containers, use a base image with an intact rpmdb or confine to a provider that works there

Example fix

# before: rpm -qa fails with a db5 error and every puppet run aborts
rm -f /var/lib/rpm/__db.*
rpm --rebuilddb
# after: 'rpm -qa | wc -l' returns a count and puppet runs complete
Defensive patterns

Strategy: validation

Validate before calling

# Ruby: verify the rpm database is queryable before a run that prefetches packages
def rpm_db_healthy?
  Puppet::Util::Execution.execute(['rpm', '-qa'], failonfail: false, combine: false).exitstatus.zero?
end

Try / catch

begin
  instances = Puppet::Type.type(:package).provider(:rpm).instances
rescue Puppet::Error => e
  raise unless e.message == 'Failed to list packages'
  Puppet.err('rpm -qa failed; run `rm -f /var/lib/rpm/__db.*; rpm --rebuilddb` then retry')
  instances = []
end

Prevention

When it happens

Trigger: 'rpm -qa' exiting non-zero: corrupted Berkeley DB (__db files) after a killed rpm/yum transaction, db lock contention with concurrent yum cron jobs, a pruned/unreadable rpmdb in minimal containers, or 'sort' failing because /tmp or /var is full.

Common situations: Interrupted yum/rpm transactions; rpm db locks held by unattended-upgrades; container base images with stripped rpm databases; disk-full conditions.

Related errors


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