puppetlabs/puppet · error · Puppet::Error

Package #{hash[:name]}, version #{hash[:ensure]} is in error

Error message

Package #{hash[:name]}, version #{hash[:ensure]} is in error state: #{hash[:error]}

What it means

dpkg.rb:162: query runs dpkg-query and parses the ${Status} field into [:desired, :error, :status, ...]; the second word is dpkg's error flag. When it is anything other than 'ok' (typically 'reinstreq' — reinstatement required), the provider raises Puppet::Error naming the package, version and error state. It surfaces dpkg database/packages in a broken, half-completed state that must be repaired before management can proceed.

Source

Thrown at lib/puppet/provider/package/dpkg.rb:162

          @resource[:name] = hash[:name]
        end
      end
      output = dpkgquery(
        "-W",
        "--showformat",
        self.class::DPKG_QUERY_FORMAT_STRING,
        @resource[:name]
      )
      hash = self.class.parse_line(output)
    rescue Puppet::ExecutionFailure
      # dpkg-query exits 1 if the package is not found.
      return { :ensure => :purged, :status => 'missing', :name => @resource[:name], :error => 'ok' }
    end

    hash ||= { :ensure => :absent, :status => 'missing', :name => @resource[:name], :error => 'ok' }

    if hash[:error] != "ok"
      raise Puppet::Error, "Package #{hash[:name]}, version #{hash[:ensure]} is in error state: #{hash[:error]}"
    end

    hash
  end

  def uninstall
    dpkg "-r", @resource[:name]
  end

  def purge
    dpkg "--purge", @resource[:name]
  end

  def hold
    Tempfile.open('puppet_dpkg_set_selection') do |tmpfile|
      tmpfile.write("#{@resource[:name]} hold\n")
      tmpfile.flush
      execute([:dpkg, "--set-selections"], :failonfail => false, :combine => false, :stdinfile => tmpfile.path.to_s)

View on GitHub (pinned to e227c27540)

Solutions

  1. Repair dpkg on the node: `dpkg --configure -a` then `apt-get -f install` (or `dpkg --remove --force-remove-reinstreq <pkg>` for a package that cannot be reconfigured).
  2. Investigate why it broke: check /var/log/dpkg.log, disk space (`df -h /var /usr`), and the failing postinst.
  3. Re-run the puppet agent once the package reports a clean status (`dpkg-query -W -f='${Status}' <pkg>` shows 'ok').

Example fix

# before: query raises 'package foo, version 1.2 is in error state: reinstreq'
# repair on the node:
#   sudo dpkg --configure -a
#   sudo apt-get -f install
# after
package { 'foo': ensure => installed }  # applies cleanly
Defensive patterns

Strategy: validation

Validate before calling

# pre-flight: any package in an error state?
out = `dpkg-query -W -f='${Status}' 2>/dev/null`.lines
bad = `dpkg --audit 2>/dev/null`
raise "dpkg needs repair (dpkg --configure -a):\n#{bad}" unless bad.empty?

Try / catch

begin
  provider.query
rescue Puppet::Error => e
  raise unless e.message =~ /is in error state/
  # run repair, then retry the puppet run once
  system('dpkg --configure -a && apt-get -f install') or raise
  retry
end

Prevention

When it happens

Trigger: A package resource (or `puppet resource package` enumeration reaching this code) for a package whose dpkg status is e.g. 'install reinstreq half-installed' — an interrupted dpkg run (killed mid-install, disk full, crash during postinst, power loss) left the package in an error state.

Common situations: dpkg interrupted by OOM/timeout during a CI agent run; disk filled mid-install; broken postinst script aborting the transaction; partially upgraded systems after a failed `apt-get upgrade`.

Related errors


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