Last active
December 21, 2015 12:29
-
-
Save kamaradclimber/6306398 to your computer and use it in GitHub Desktop.
Pre convergence notifications
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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