Class: VagrantPlugins::Exec::Command

Inherits:
Object
  • Object
show all
Includes:
SSHHelper
Defined in:
lib/vagrant-exec/command.rb

Constant Summary

Constants included from SSHHelper

SSHHelper::SSH_CONFIG

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.synopsisObject



7
8
9
# File 'lib/vagrant-exec/command.rb', line 7

def self.synopsis
  'executes commands in virtual machine'
end

Instance Method Details

#executeObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/vagrant-exec/command.rb', line 11

def execute
  cmd, cmd_args = parse_args
  cmd && cmd_args or return nil

  # Execute the actual SSH
  with_target_vms(nil, single_target: true) do |vm|
    constructor = CommandConstructor.new(cmd, vm.config.exec.commands)
    command = constructor.construct_command
    command << ' ' << cmd_args.join(' ') if cmd_args.any?

    @logger.info("Executing single command on remote machine: #{command}")
    ssh_opts = {extra_args: ['-q']} # make it quiet
    env = vm.action(:ssh_run, ssh_run_command: command, ssh_opts: ssh_opts)

    status = env[:ssh_run_exit_status] || 0
    return status
  end
end