- From: Bryan McLellan <
>
- To: "
" <
>
- Subject: [chef] Re: mixliv command run_command executed at compile time ?
- Date: Fri, 7 Feb 2014 13:28:06 -0500
On Fri, Feb 7, 2014 at 1:07 PM, Cyril Scetbon
<
>
wrote:
>
When the command used in the Mixlib::ShellOut.new does not exist, chef
>
exits with a compilation error
Yes, it will fail if you tell it to run a command that dos not exist.
>
In the following example it should start and exists as it should not find
>
package whois2
>
>
include_recipe "apt"
>
>
package "whois2" do
>
action :install
>
end
>
>
cmd = Mixlib::ShellOut.new("echo2 ok")
>
cmd.run_command
I'm guessing you're expecting it to fail on on the package line,
because that package is made up and doesn't exist, but it's failing on
the later line.
This is because the chef-client run reads the recipes to create the
Resource Collection (often called compilation), before it actually
makes any changes to the system by running the providers (often called
convergence). The first time it reads the package resource, it hasn't
tried to install it yet, so it doesn't fail even though it doesn't
exist. But your ruby code below that (the mixlib calls) is executed in
that first phase, and since the ruby code fails, the recipe fails
there.
http://docs.opscode.com/essentials_nodes_chef_run.html
If you put your ruby code in a "ruby_block" resource, it wouldn't
actually be run until the later phase. The purpose of a ruby_block
resources is to be able to run and notify ruby code during convergence
in a specific order.
http://docs.opscode.com/resource_ruby_block.html
ruby_block "run a command that doesn't exist" do
block do
cmd = Mixlib::ShellOut.new("echo2 ok")
cmd.run_command
end
end
Bryan
Archive powered by MHonArc 2.6.16.