- From: Cyril Scetbon <
>
- To: "
" <
>
- Subject: [chef] Re: Re: mixliv command run_command executed at compile time ?
- Date: Fri, 7 Feb 2014 21:23:47 +0100
Thank you guys you're right
The ruby_block resource is used to execute Ruby code during a chef-client run. Ruby code in theruby_block resource is evaluated with other resources during convergence, whereas Ruby code outside of a ruby_block resource is evaluated before other resources, as the recipe is compiled.
Cyril Scetbon Le 7 févr. 2014 à 19:28, Bryan McLellan <
">
> a écrit : 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 onthe later line.This is because the chef-client run reads the recipes to create theResource Collection (often called compilation), before it actuallymakes any changes to the system by running the providers (often calledconvergence). The first time it reads the package resource, it hasn'ttried to install it yet, so it doesn't fail even though it doesn'texist. But your ruby code below that (the mixlib calls) is executed inthat first phase, and since the ruby code fails, the recipe failsthere.http://docs.opscode.com/essentials_nodes_chef_run.htmlIf you put your ruby code in a "ruby_block" resource, it wouldn'tactually be run until the later phase. The purpose of a ruby_blockresources is to be able to run and notify ruby code during convergencein a specific order.http://docs.opscode.com/resource_ruby_block.htmlruby_block "run a command that doesn't exist" do block do cmd = Mixlib::ShellOut.new("echo2 ok") cmd.run_command endendBryan
|
Archive powered by MHonArc 2.6.16.