Search code examples
rubychef-infrarecipe

Chef - Get output of remote_execute resource


Usually I get command outputs in variables like this: res = `find . -name my_script.sh`. Then I can parse the output for what I am interested in.

How can I get the output of a command executed by a machine_execute resource ?

machine_execute 'Check IPA status' do
  command 'ipactl status'
  machine 'IPA_Admin_server'
end

Solution

  • You can't, Chef resources don't generally have outputs. In some cases the support an output API (like the AWS provisioning driver's aws_object helpers) but for something like this you would need to get the low-level Machine object and call its execute method. Take a look at how the resource is implemented for an example. You might also want to skip Provisioning's transport layer and use Train as we are probably going to try and centralize on that library.