Skip to content

Instantly share code, notes, and snippets.

@kamaradclimber
Last active December 21, 2015 12:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kamaradclimber/6306398 to your computer and use it in GitHub Desktop.
Save kamaradclimber/6306398 to your computer and use it in GitHub Desktop.
Pre convergence notifications
Chef::Config[:why_run] = true
t = package "cassandra" do
version '42'
action :nothing
end
t.run_action(:install)
would_update = t.updated_by_last_action?
Chef::Config[:why_run] = false
execute "downtime in supervision" do
cmd "do it!"
only_if { t.updated_by_last_action? } #this doesn't work
end
execute "dowtime in supervision" do
cmd "do it!"
only_if { would_update} #this works
end
#after resetting why run everything runs as usual
b= package "screen"
#so we can now really update the package
package "cassandra" do
version '42'
action :install
end
#resource prehook
actions :run
default_action :run
attribute :resource, :kind_of => Resource, :required => true
attribute :hooked_action, :kind_of => Symbol, :default => :nothing
#provider prehook
action :run do
previous_why_run_mode = Chef::Config[:why_run]
Chef::Config[:why_run] = true
new_resource.resource.run_action(new_resource.hooked_action)
would_be_updated = new_resource.resource.updated_by_last_action?
Chef::Config[:why_run] = previous_why_run_mode
new_resource.resource.action(new_resource.hooked_action)
new_resource.updated_by_last_action(would_be_updated)
end
#Usage
p = package "cassandra" do
action :nothing
end
execute "downtime" do
command "touch /tmp/downtime"
action :nothing
end
prehook "toto" do
resource p
hooked_action :install
notifies :run, "execute[downtime]"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment