puppetlabs/puppet · error · Puppet::Error

Could not find package %{name}

Error message

Could not find package %{name}

What it means

When a specific version was requested (should is set), the yum provider re-queries rpm after install; a nil query means the package still is not installed and it raises Puppet::Error 'Could not find package'. Distinct from the output-scan error: yum's output looked fine ('No package ... available.' not seen) yet nothing matching is installed - typically a virtual/provides name or a transaction that silently skipped work.

Source

Thrown at lib/puppet/provider/package/yum.rb:323

          operation = update_command
        end
      end
    end

    # Yum on el-4 and el-5 returns exit status 0 when trying to install a package it doesn't recognize;
    # ensure we capture output to check for errors.
    no_debug = Puppet.runtime[:facter].value('os.release.major').to_i > 5 ? ["-d", "0"] : []
    command = [command(:cmd)] + no_debug + ["-e", error_level, "-y", install_options, operation, wanted].compact
    output = execute(command)

    if output.to_s =~ /^No package #{wanted} available\.$/
      raise Puppet::Error, _("Could not find package %{wanted}") % { wanted: wanted }
    end

    # If a version was specified, query again to see if it is a matching version
    if should
      is = query
      raise Puppet::Error, _("Could not find package %{name}") % { name: name } unless is

      version = is[:ensure]
      # FIXME: Should we raise an exception even if should == :latest
      # and yum updated us to a version other than @param_hash[: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
    upd = self.class.latest_package_version(@resource[:name], disablerepo, enablerepo, disableexcludes)
    if upd.nil?
      # Yum didn't find updates, pretend the current version is the latest
      debug "Yum didn't find updates, current version (#{properties[:ensure]}) is the latest"
      version = properties[:ensure]
      raise Puppet::DevError, _("Tried to get latest on a missing package") if version == :absent || version == :purged

View on GitHub (pinned to e227c27540)

Solutions

  1. After the failure run 'rpm -q <name>'; if empty, manage the real owning package name instead of the alias
  2. Remove --skip-broken style install_options so failed transactions raise instead of skipping silently
  3. Set allow_virtual => true on the resource so query falls back to rpm --whatprovides
  4. Check repo exclude= lines and disableexcludes - the package may install under a different name or be filtered

Example fix

// before - 'mysql' is a virtual provides; community-mysql installs, then rpm -q mysql is empty
package { 'mysql':
  ensure => '5.5.60-1.el7',
}
// after - real package name plus virtual-aware queries
package { 'community-mysql':
  ensure        => '5.5.60-1.el7',
  allow_virtual => true,
}
Defensive patterns

Strategy: validation

Validate before calling

# Ruby: ensure rpm will be able to see the name after yum resolves it
def queryable_after_install?(name, allow_virtual = false)
  cmd = ['rpm', '-q', name]
  cmd << '--whatprovides' if allow_virtual
  Puppet::Util::Execution.execute(cmd, failonfail: false).exitstatus.zero? || allow_virtual
end

Type guard

# Heuristic: names rpm indexes indirectly (file paths, provides aliases) need virtual queries
def likely_virtual_name?(name)
  name.start_with?('/')
end

Try / catch

begin
  provider.install
rescue Puppet::Error => e
  raise unless e.message =~ /Could not find package/
  raise Puppet::Error, "#{resource[:name]} looks virtual - manage the real package name or set allow_virtual => true"
end

Prevention

When it happens

Trigger: ensure => <version> where the resource name is a provides-style alias that yum resolves to a real package while 'rpm -q <name>' finds nothing; install_options like --skip-broken letting yum skip the transaction; excludes via disableexcludes hiding the result.

Common situations: Managing virtual names ('mysql', 'webserver', file paths); --skip-broken options copied from runbooks; version-range ensures on el7; names whose owning package differs across releases.

Related errors


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