Description
When using a constraint (like ~> 1.0) if a newer gem exists in the default source (e.g. 1.5), but not the source provided in chef_gem (e.g. 1.1) it will try to install the "latest" version (e.g 1.5) against the source in chef_gem resulting in a failure. This occurs even if the following are set:
clear_sources true
include_default_source false
It appears that --clear-sources is not passed to candidate_version_from_remote, but it is in install_via_gem_command. This explains why it's not just installing the latest version from the default source, but a mix.
I am not familiar with the codebase, however I've tried to provide a simple fix in: #16267
Chef Version
18.11.11
Platform Version
Ubuntu 24.04
Replication Case
Default source is rubygems.org. Use a resource like this:
chef_gem 'cool-gem' do
action :install
clear_sources true
include_default_source false
source 'https://cool-rubygems.example.com'
version '~> 1.0'
end
If rubygems.org has 1.5 and cool-rubygems.example.com only has up to 1.2, then the above resource will try to install 1.5 from cool-rubygems.example.com, which fails.
Client Output
I can provide sanitised logs if my investigation is incorrect.
Stacktrace
I can provide a sanitised stacktrace if my investigation is incorrect.
Description
When using a constraint (like
~> 1.0) if a newer gem exists in the default source (e.g.1.5), but not thesourceprovided inchef_gem(e.g.1.1) it will try to install the "latest" version (e.g1.5) against thesourceinchef_gemresulting in a failure. This occurs even if the following are set:clear_sources trueinclude_default_source falseIt appears that
--clear-sourcesis not passed tocandidate_version_from_remote, but it is ininstall_via_gem_command. This explains why it's not just installing the latest version from the default source, but a mix.I am not familiar with the codebase, however I've tried to provide a simple fix in: #16267
Chef Version
18.11.11
Platform Version
Ubuntu 24.04
Replication Case
Default source is
rubygems.org. Use a resource like this:If
rubygems.orghas1.5andcool-rubygems.example.comonly has up to1.2, then the above resource will try to install1.5fromcool-rubygems.example.com, which fails.Client Output
I can provide sanitised logs if my investigation is incorrect.
Stacktrace
I can provide a sanitised stacktrace if my investigation is incorrect.