Vagrant plugin: How to capture machine.action output

225 Views Asked by At

I started writing a plugin for Vagrant, which will add a command. Within the Command#execute I need to capture the :ssh_run output. Right now output goes straight to stdout. Small test snippet from the command:

with_target_vms(@argv, single_target: true) do |vm|
  vm.action(:ssh_run, ssh_run_command: 'tail -50 /var/log/boot.log')
end

Has anyone an idea how to do it? Maybe vm.action itself isn't the right way?

Thanks a lot in advance

Sebastian

1

There are 1 best solutions below

0
On

That was fast. @effhaa told me the on another channel.

with_target_vms(@argv, single_target: true) do |vm|
  result = []
  vm.communicate.sudo('tail -50 /var/log/boot.log') do |type, data|
    if type == :stdout
      result = data.split(/[\r\n]+/)
    end
  end
end