module Kitchen::Yansible::Tools::Exec

Public Instance Methods

check_command(command, args: '') click to toggle source
# File lib/kitchen-yansible/tools/exec.rb, line 31
def check_command(command, args: '')
  "command -v #{command}" + "#{(" #{args}" unless args.empty?)}"
end
command_exists(command) click to toggle source
# File lib/kitchen-yansible/tools/exec.rb, line 35
def command_exists(command)
  check_command(command, :args => '&>/dev/null')
end
detect_platform() click to toggle source
# File lib/kitchen-yansible/tools/exec.rb, line 104
def detect_platform
  @instance.driver.diagnose[:name] == 'docker' ?
    @instance.driver.diagnose[:platform].to_s : @instance.platform.name.to_s
end
execute_local_command(command, env: {}, opts: {}, print_stdout: false, return_stdout: false) click to toggle source
# File lib/kitchen-yansible/tools/exec.rb, line 74
def execute_local_command(command, env: {}, opts: {}, print_stdout: false, return_stdout: false)
  print_cmd_parameters(command, env)

  # noinspection RubyUnusedLocalVariable
  Open3.popen3(env, command, opts) { |stdin, stdout, stderr, thread|
    if print_stdout
      while (line = stdout.gets)
        puts line
      end
    end
    proc = thread.value

    print_cmd_error(stderr, proc)
    return_stdout ? stdout.read : proc.success?
  }
end
local_command_exists(command) click to toggle source
# File lib/kitchen-yansible/tools/exec.rb, line 43
def local_command_exists(command)
  "#{local_command_path(command, :args => '&>/dev/null')}"
end
local_command_path(command, args: '') click to toggle source
# File lib/kitchen-yansible/tools/exec.rb, line 39
def local_command_path(command, args: '')
  system(check_command(command, args))
end
print_cmd_error(stderr, proc) click to toggle source
print_cmd_parameters(command, env = {}) click to toggle source
sudo(script) click to toggle source

Taken from github.com/test-kitchen/test-kitchen/blob/master/lib/kitchen/provisioner/base.rb

# File lib/kitchen-yansible/tools/exec.rb, line 100
def sudo(script)
  "sudo -E #{script}"
end
sudo_env(pm) click to toggle source

Helpers

# File lib/kitchen-yansible/tools/exec.rb, line 92
def sudo_env(pm)
  s = @config[:https_proxy] ? "https_proxy=#{@config[:https_proxy]}" : nil
  p = @config[:http_proxy] ? "http_proxy=#{@config[:http_proxy]}" : nil
  n = @config[:no_proxy] ? "no_proxy=#{@config[:no_proxy]}" : nil
  p || s ? "#{sudo('env')} #{p} #{s} #{n} #{pm}" : "#{sudo(pm)}"
end
unindent(s) click to toggle source
# File lib/kitchen-yansible/tools/exec.rb, line 27
def unindent(s)
  s.gsub(/^#{s.scan(/^[ \t]+(?=\S)/).min}/, '')
end