Module: PEBuild::OnMachine

Instance Method Summary collapse

Instance Method Details

#on_machine(machine, cmd, **options) ⇒ void

This method returns an undefined value.

Execute a command on a machine and log output

This method invokes the execute method of the machine's communicator and logs any resulting output at info level.

Parameters:

  • machine (Vagrant::Machine)

    The Vagrant machine on which to run the command.

  • cmd (String)

    The command to run.

  • options (Hash)

    Additional options to pass to the execute method of the communicator.

Options Hash (**options):

  • :sudo (Boolean)

    A flag which controls whether the command is executed with elevated privilages. Defaults to true.



18
19
20
21
22
23
24
25
# File 'lib/pe_build/on_machine.rb', line 18

def on_machine(machine, cmd, **options)
  options[:sudo] = true unless options.has_key?(:sudo)

  machine.communicate.execute(cmd, options) do |type, data|
    color = (type == :stdout) ? :green : :red
    machine.ui.info(data.chomp, :color => color, :prefix => true)
  end
end