On Tuesday, August 28, 2012 at 6:35 AM, Tom wrote:
Hi,
Is it possible to make a resource notify, (and thus run) an entire recipe.
For example:
I wish to upgrade a package, but it depends on certain resources being executed - either before or after the package installation.
Is it possible to do something like:
package "application" do
action :upgrade
notifies recipe[pre_inst]
end
?
No, you can't do that, but you can have multiple notifications by putting multiple calls to notifies in the resource declaration. There may be jacky ways to do exactly what you want using ruby_block resources and internal Chef APIs, but I'd recommend against it.
what does recipe[pre_inst] do? Is there any particular reason you can not
include pre_inst (or vice versa) and notify specific resources from
pre_inst? Given that you can have multiple notification there may be a
cleaner solution.
In the end I have solved this one by doing the following in a recipe:
node.role.packages.singlenode.each do |pkg|
p = package "#{pkghost}-#{pkg}" do
action :nothing
end
p.run_action(:upgrade)
if p.updated_by_last_action?
include_recipe "install::single-node"
end
end
Which runs the recipe post install, and works against an array of packages.
I would like to find a way to pre-install too, but this works for now.
what does recipe[pre_inst] do? Is there any particular reason you can not
include pre_inst (or vice versa) and notify specific resources from
pre_inst? Given that you can have multiple notification there may be a
cleaner solution.