I want to abort a recipe at the run time based on a certain condition but use raise or Chef::Application.fatal! as described in this post How do you abort/end a Chef run? my recipe is exiting at the compilation time only.
Here is what I am trying (a part of my script):
execute "Execute somehthing" do
cwd node['abc']['dir']
command "something >> #{results}"
node.default['success'] = "false"
notifies :run, "ruby_block[jobFailure]", :delayed
not_if "cd #{node['abc']['dir']} && somecommand >> #{results}"
end
ruby_block "jobFailure" do
raise "Exiting the script as the job has failed" if (node.default['success'] == "false")
action :nothing
end
But while running the above script I am getting the error as Chef is exiting at the compilation time only giving the below error:
Running handlers:
[2014-10-27T17:17:03+00:00] ERROR: Running exception handlers
Running handlers complete
[2014-10-27T17:17:03+00:00] ERROR: Exception handlers complete
[2014-10-27T17:17:03+00:00] FATAL: Stacktrace dumped to c:/Users/manish.a.joshi/
.chef/local-mode-cache/cache/chef-stacktrace.out
Chef Client failed. 0 resources updated in 12.400772 seconds
[2014-10-27T17:17:03+00:00] FATAL: RuntimeError: Exiting the script as the job has failed
Can anyone let me know if there is a way to only execute the raise command based on a condition?