ottodidakt
ottodidakt

Reputation: 3741

Why is chef complaining about candidate version here?

I have this snippet in a chef-solo recipe

package "myserver" do
  action :upgrade
  source "/tmp/myserver-12.4.0-16052.noarch.rpm"
  provider Chef::Provider::Package::Rpm
end

But chef says:

INFO: Processing package[myserver] action upgrade (cbgd::default line 16)
DEBUG: package[myserver] checking rpm status
DEBUG: package[myserver] checking install state
DEBUG: package[myserver] current version is 12.4.0-16050
DEBUG: package[myserver] no candidate version - nothing to do
INFO: Chef Run complete in 2.621177 seconds

I was expecting the upgrade to go through. A simple rpm -Uvh works fine. Any ideas?

Upvotes: 1

Views: 1441

Answers (1)

jtimberman
jtimberman

Reputation: 8258

It doesn't really make sense to use the upgrade action when you're installing a single package from a known source file. Change the action to :install. Also, Chef has a shortcut resource for rpm packages, `rpm_package, so you don't need the provider line (it uses it automatically.

rpm_package "myserver" do
  action :install
  source "/tmp/myserver-12.4.0-16052.noarch.rpm"
end

Finally, Chef's package resources use :install by default, so you don't need that either, actually.

rpm_package "myserver" do
  source "/tmp/myserver-12.4.0-16052.noarch.rpm"
end

To set the package name as a node attribute, you can do that in a cookbook's attributes/default.rb, in a role that is applied to the node, or on the node object itself (in a recipe, or editing the node object on the chef server). The reason for each location varies, but the general rule is:

  • use cookbookname/attributes/default.rb for "sane defaults" that could be overridden elsewhere (role, node)
  • use role attributes for setting across a lot of systems that share functionality (all webservers having a "webserver" role, for example).
  • use node attributes directly for special and unique snowflakes. We don't recommend snowflakes, of course :-).

To do it in an attributes file:

default['myserver']['package_name'] = 'myserver-12.4.0-16052.noarch.rpm'

Then in the resource:

rpm_package "myserver" do
  source "/tmp/#{node['myserver']['package_name']}"
end

See the Opscode Chef documentation for information on Attribute Precedence, Attribute Files in cookbooks. Roles are a Ruby DSL, or straight JSON.

Upvotes: 2

Related Questions