puppetlabs/puppet · error · Puppet::Error

Failed to update to version %{should}, got version %{version

Error message

Failed to update to version %{should}, got version %{version} instead

What it means

With a version pinned (or a range like '>= 2.0'), after install the yum provider queries the installed version and requires insync?(version) against should; on mismatch it raises 'Failed to update to version ... got ... instead'. It means yum completed but delivered something other than the requested NEVRA - moved repos, obsoletes substitutions, or ranges the installed version does not satisfy.

Source

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

    # 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

      version
    else
      # FIXME: there could be more than one update for a package
      # because of multiarch
      "#{upd[:epoch]}:#{upd[:version]}-#{upd[:release]}"

View on GitHub (pinned to e227c27540)

Solutions

  1. Compare what yum offers: 'yum --showduplicates list <name>' and align ensure to an available NEVRA including epoch
  2. If a downgrade is intended, clear blockers: remove /etc/yum/pluginconf.d/versionlock.list entries and protected packages
  3. For obsoleted packages, manage the replacing package name instead of the old one
  4. Refresh metadata ('yum clean expire-cache') and re-run the agent

Example fix

// before - pinned version the repo no longer serves; yum installs 2.9.27 and the provider aborts
package { 'ansible':
  ensure => '2.9.9-1.el7',
}
// after - pin matches a version still listed by 'yum --showduplicates list ansible'
package { 'ansible':
  ensure => '2.9.27-1.el7',
}
Defensive patterns

Strategy: validation

Validate before calling

# Ruby: confirm the exact pin is served by an enabled repo before applying
def yum_version_available?(name, version)
  out = Puppet::Util::Execution.execute(
    ['yum', '--showduplicates', '--qf', '%{EPOCH}:%{VERSION}-%{RELEASE}', 'list', 'available', name],
    failonfail: false
  ).to_s
  out.lines.any? { |l| l.include?(version) }
end

Try / catch

begin
  provider.install
rescue Puppet::Error => e
  raise unless e.message =~ /Failed to update to version/
  should = e.message[/to version (\S+),/, 1]
  got = e.message[/got version (\S+)/, 1]
  Puppet.err("wanted #{should}, repo served #{got} - check `yum --showduplicates list #{resource[:name]}`")
  raise
end

Prevention

When it happens

Trigger: ensure => '2.0-1.el7' when enabled repos only serve a newer build (yum installs it, mismatch raises); obsoletes replacing the named package (docker-ce vs docker-engine); version-range ensures where the resulting version falls outside the range; downgrades blocked by versionlock.

Common situations: Drifting mirrors between CI and production; stale yum metadata; versionlock plugin entries; major-version upgrades where obsoletes reroute packages.

Related errors


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