Reputation: 3741
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
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:
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