Module: VagrantAutoDNS::Cap::Common

Included in:
GetIP, InstallIptables, RedirectDNS
Defined in:
lib/vagrant-autodns/cap/common.rb

Instance Method Summary collapse

Instance Method Details

#iptables_location(machine) ⇒ Object

Get iptables bin location



30
31
32
33
34
35
36
37
38
39
# File 'lib/vagrant-autodns/cap/common.rb', line 30

def iptables_location(machine)
  iptables_location = [
    'iptables',
    '/bin/iptables',
    '/sbin/iptables',
    '/usr/bin/iptables',
    '/usr/sbin/iptables'
  ].map{|l| "command -v #{l}"}.join(' || ')
  run_command(machine, iptables_location)
end

#run_command(machine, command, show_full_result = false) ⇒ Object

Run command on remote machine



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/vagrant-autodns/cap/common.rb', line 14

def run_command(machine, command, show_full_result = false)
  std_out = []
  std_err = []
  exit_code = machine.communicate.sudo(command, :error_check => false) do |type, data|
    next if data =~ /stdin: is not a tty/
    std_out << data if type == :stdout
    std_err << data if type == :stderr
  end
  full_result = {
    :exit_code => exit_code,
    :stdout => std_out.join.strip,
    :stderr => std_err.join.strip
  }
  show_full_result ? full_result : full_result[:stdout]
end