Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Override the chef bash return code

I am running a chef recipie to install Websphere fixpacks. The fixpack retuns and exitcode [2] which is for partial install. Its an expected behaviour, but chef is just taking it as an error. Is there any way to override it.

I want chef to move ahead with the next task, even if the return exit code is [2]

================================================================================
Error executing action `run` on resource 'bash[was-install-fixpacks]'
================================================================================


Mixlib::ShellOut::ShellCommandFailed
------------------------------------
Expected process to exit with [0], but received '2'
like image 976
Saurav Avatar asked Jun 07 '13 02:06

Saurav


People also ask

How do I run a shell script in chef?

You'd put your script in files/default/. In default. rb, which would have a 'cookbook_file' resource that places the script onto the host, and the above execute command. You'd then upload the cookbook to the chef server and add recipe[COOKBOOKNAME] to the runlist of your node.

How do you execute a command in a chef's recipe?

Use the execute resource to execute a single command. Commands that are executed with this resource are (by their nature) not idempotent, as they are typically unique to the environment in which they are run. Use not_if and only_if to guard this resource for idempotence.

What is guard in chef?

Chef-Guard is a feature rich Chef add-on that protects your Chef server from untested and uncommitted (i.e. potentially dangerous) cookbooks by running several validations and checks during the cookbook upload process.

What are phases of Chef execution?

There are two stages to a chef run though. A compile phase, to organise what resources need to be run and resolve all variables. Then a run phase where each resource is actually executed. You can write recipes that trigger actions during the compile phase which may make it seem out of order.


1 Answers

A quick look into the documentation reveals the parameter returns:

The return value for a command. This may be an array of accepted values. An exception is raised when the return value(s) do not match. Default value: 0.

Example:

bash "was-install-fixpacks" do
  command ..
  returns [0, 2]
end
like image 150
StephenKing Avatar answered Oct 02 '22 13:10

StephenKing