Class: VagrantPlugins::Ansible::Helpers

Inherits:
Object
  • Object
show all
Defined in:
lib/helpers.rb

Class Method Summary collapse

Class Method Details

.as_array(v) ⇒ Object



38
39
40
# File 'lib/helpers.rb', line 38

def self.as_array(v)
  v.kind_of?(Array) ? v : [v]
end

.as_list_argument(v) ⇒ Object



34
35
36
# File 'lib/helpers.rb', line 34

def self.as_list_argument(v)
  v.kind_of?(Array) ? v.join(',') : v
end

.expand_path_in_unix_style(path, base_dir) ⇒ Object



28
29
30
31
32
# File 'lib/helpers.rb', line 28

def self.expand_path_in_unix_style(path, base_dir)
  # Remove the possible drive letter, which is added
  # by `File.expand_path` when running on a Windows host
  File.expand_path(path, base_dir).sub(/^[a-zA-Z]:/, "")
end

.stringify_ansible_playbook_command(env, command) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/helpers.rb', line 6

def self.stringify_ansible_playbook_command(env, command)
  shell_command = ''
  env.each_pair do |k, v|
    if k == 'ANSIBLE_SSH_ARGS'
      shell_command += "#{k}='#{v}' "
    else
      shell_command += "#{k}=#{v} "
    end
  end

  shell_arg = []
  command.each do |arg|
    if arg =~ /(--start-at-task|--limit)=(.+)/
      shell_arg << "#{$1}='#{$2}'"
    else
      shell_arg << arg
    end
  end

  shell_command += shell_arg.join(' ')
end