How can I put the output of a Chef 'execute resource' into a variable -
i'd put output of shell command variable later use in chef recipe.
in bash output=`tail -1 file.txt`
, echo $output
can 'execute resource' can use result later in recipe?
while graham's solution seemed work @ first, found out chef::mixin:shellout
ruby_block "check_curl_command_output" block #tricky way load chef::mixin::shellout utilities chef::resource::rubyblock.send(:include, chef::mixin::shellout) curl_command = 'curl --write-out %{http_code} --silent --output /dev/null '+node['url'] curl_command_out = shell_out(curl_command) if curl_command.stdout == "302" ... else ... end end action :create end
chef::mixin:shellout particularly useful if need run command specific user (cf. http://www.slideshare.net/opscode/chef-conf-windowsdougireton ):
ruby_block "run_command_as" block chef::resource::rubyblock.send(:include,chef::mixin::shellout) add_group = shell_out("your command", { :user => "my_user", :password => "my_password", :domain => "mycorp.com" } ) end end
Comments
Post a Comment