Overwriting a component version doesn't overwrite the generated download URL.
Consider a simple setup such as
node.override["prometheus-platform"]["components"]["prometheus"]["version"] = "2.27.1"
node.override["prometheus-platform"]["components"]["prometheus"]["sha"] = "ce637d0167d5e6d2561f3bd37e1c58fe8601e13e4e1ea745653c068f6e1317ae"
node.override["prometheus-platform"]["components"]["prometheus"]["install?"] = true
include_recipe "prometheus-platform"
On current master, this overwrites the 2.17.2
version:
'prometheus' => {
'install?' => false,
'version' => '2.17.2',
'sha' => 'a8ca17b845df4967ff5ef9f9b2c7c98568104e777c9f9a4eb1bc409726089626'
},
The above fails to install: the attributes get overwritten but the download still happens with the default version
.
System Info:
------------
chef_version=16.12.3
platform=ubuntu
platform_version=16.04
ruby=ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-linux]
program_name=/opt/chef/bin/chef-client
executable=/opt/chef/bin/chef-client
================================================================================
Error executing action `install` on resource 'ark[prometheus]'
================================================================================
Chef::Exceptions::ChecksumMismatch
----------------------------------
remote_file[/tmp/kitchen/cache/prometheus-2.27.1.tar.gz] (/tmp/kitchen/cache/cookbooks/ark/resources/default.rb line 64) had an error: Chef::Exceptions::ChecksumMismatch: Checksum on resource (ce637d...) does not match checksum on content (a8ca17...)
We can see that this is what's happening by looking a bit more down on in the chef-client log:
Compiled Resource:
------------------
# Declared in /tmp/kitchen/cache/cookbooks/prometheus-platform/recipes/install.rb:45:in `block in from_file'
ark("prometheus") do
action [:install]
updated true
updated_by_last_action true
default_guard_interpreter :default
declared_type :ark
cookbook_name "prometheus-platform"
recipe_name "install"
url "https://github.com/prometheus/prometheus/releases/download/v2.17.2/prometheus-2.17.2.linux-amd64.tar.gz"
prefix_root "/opt"
prefix_home "/opt"
prefix_bin "/opt/bin"
has_binaries []
checksum "ce637d0167d5e6d2561f3bd37e1c58fe8601e13e4e1ea745653c068f6e1317ae"
version "2.27.1"
extension "tar.gz"
home_dir "/opt/prometheus"
owner "root"
path "/opt/prometheus-2.27.1"
release_file "/tmp/kitchen/cache/prometheus-2.27.1.tar.gz"
end
Note the url
parameter.
This is not the end of the world as we can build and set the URL ourselves.
def install_prometheus_component(component_name, version, sha)
node.override["prometheus-platform"]["components"][component_name]["version"] = version
node.override["prometheus-platform"]["components"][component_name]["sha"] = sha
node.override["prometheus-platform"]["components"][component_name]["install?"] = true
node.override["prometheus-platform"]["components"][component_name]["url"] =
"https://github.com/prometheus/#{component_name}/releases/download/v#{version}/#{component_name}-#{version}.linux-amd64.tar.gz"
end
install_prometheus_component("prometheus", "2.27.1", "ce637d0167d5e6d2561f3bd37e1c58fe8601e13e4e1ea745653c068f6e1317ae")
# whatever other components you may want go here
# …
include_recipe "prometheus-platform"