{"record":{"id":"5f4588755f0e6194","repo":"puppetlabs/puppet","slug":"failed-to-update-to-version-should-got-version-5f4588","errorCode":null,"errorMessage":"Failed to update to version %{should}, got version %{version} instead","messagePattern":"Failed to update to version %(.+?), got version %(.+?) instead","errorType":"exception","errorClass":"Puppet::Error","httpStatus":null,"severity":"error","filePath":"lib/puppet/provider/package/yum.rb","lineNumber":328,"sourceCode":"    # Yum on el-4 and el-5 returns exit status 0 when trying to install a package it doesn't recognize;\n    # ensure we capture output to check for errors.\n    no_debug = Puppet.runtime[:facter].value('os.release.major').to_i > 5 ? [\"-d\", \"0\"] : []\n    command = [command(:cmd)] + no_debug + [\"-e\", error_level, \"-y\", install_options, operation, wanted].compact\n    output = execute(command)\n\n    if output.to_s =~ /^No package #{wanted} available\\.$/\n      raise Puppet::Error, _(\"Could not find package %{wanted}\") % { wanted: wanted }\n    end\n\n    # If a version was specified, query again to see if it is a matching version\n    if should\n      is = query\n      raise Puppet::Error, _(\"Could not find package %{name}\") % { name: name } unless is\n\n      version = is[:ensure]\n      # FIXME: Should we raise an exception even if should == :latest\n      # and yum updated us to a version other than @param_hash[:ensure] ?\n      raise Puppet::Error, _(\"Failed to update to version %{should}, got version %{version} instead\") % { should: should, version: version } unless\n        insync?(version)\n    end\n  end\n\n  # What's the latest package version available?\n  def latest\n    upd = self.class.latest_package_version(@resource[:name], disablerepo, enablerepo, disableexcludes)\n    if upd.nil?\n      # Yum didn't find updates, pretend the current version is the latest\n      debug \"Yum didn't find updates, current version (#{properties[:ensure]}) is the latest\"\n      version = properties[:ensure]\n      raise Puppet::DevError, _(\"Tried to get latest on a missing package\") if version == :absent || version == :purged\n\n      version\n    else\n      # FIXME: there could be more than one update for a package\n      # because of multiarch\n      \"#{upd[:epoch]}:#{upd[:version]}-#{upd[:release]}\"","sourceCodeStart":310,"sourceCodeEnd":346,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/provider/package/yum.rb#L310-L346","documentation":"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.","triggerScenarios":"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.","commonSituations":"Drifting mirrors between CI and production; stale yum metadata; versionlock plugin entries; major-version upgrades where obsoletes reroute packages.","solutions":["Compare what yum offers: 'yum --showduplicates list <name>' and align ensure to an available NEVRA including epoch","If a downgrade is intended, clear blockers: remove /etc/yum/pluginconf.d/versionlock.list entries and protected packages","For obsoleted packages, manage the replacing package name instead of the old one","Refresh metadata ('yum clean expire-cache') and re-run the agent"],"exampleFix":"// before - pinned version the repo no longer serves; yum installs 2.9.27 and the provider aborts\npackage { 'ansible':\n  ensure => '2.9.9-1.el7',\n}\n// after - pin matches a version still listed by 'yum --showduplicates list ansible'\npackage { 'ansible':\n  ensure => '2.9.27-1.el7',\n}","handlingStrategy":"validation","validationCode":"# Ruby: confirm the exact pin is served by an enabled repo before applying\ndef yum_version_available?(name, version)\n  out = Puppet::Util::Execution.execute(\n    ['yum', '--showduplicates', '--qf', '%{EPOCH}:%{VERSION}-%{RELEASE}', 'list', 'available', name],\n    failonfail: false\n  ).to_s\n  out.lines.any? { |l| l.include?(version) }\nend","typeGuard":null,"tryCatchPattern":"begin\n  provider.install\nrescue Puppet::Error => e\n  raise unless e.message =~ /Failed to update to version/\n  should = e.message[/to version (\\S+),/, 1]\n  got = e.message[/got version (\\S+)/, 1]\n  Puppet.err(\"wanted #{should}, repo served #{got} - check `yum --showduplicates list #{resource[:name]}`\")\n  raise\nend","preventionTips":["Derive version pins from repo queries ('yum --showduplicates') in CI, never by hand","Clear versionlock entries and protected-packages conflicts before downgrade plans","Watch obsoletes mappings during major OS upgrades and rename resources accordingly"],"tags":["yum","version-mismatch","version-pin","obsoletes","rhel"],"backgroundTag":"version-mismatch","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}