9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/vagrant-exec/command.rb', line 9
def execute
cmd, cmd_args = parse_args
cmd && cmd_args or return nil
with_target_vms(nil, single_target: true) do |vm|
settings = vm.config.exec._parsed_commands
passed_command, constructed_command = cmd.dup, ''
settings.reverse.each do |command|
if command_matches?(command[:cmd], passed_command) && !directory_added?
constructed_command << add_directory(command[:opts][:directory])
end
end
settings.each do |command|
if command_matches?(command[:cmd], passed_command)
constructed_command << add_env(command[:opts][:env])
end
end
settings.each do |command|
if command_matches?(command[:cmd], passed_command)
constructed_command << add_prepend(command[:opts][:prepend])
end
end
constructed_command << passed_command
constructed_command << ' ' << cmd_args.join(' ') if cmd_args.any?
@logger.info("Executing single command on remote machine: #{constructed_command}")
ssh_opts = { extra_args: ['-q'] }
env = vm.action(:ssh_run, ssh_run_command: constructed_command, ssh_opts: ssh_opts)
status = env[:ssh_run_exit_status] || 0
return status
end
end
|