Class: Ansible::Config::DefaultConfig

Inherits:
Struct
  • Object
show all
Defined in:
lib/ansible/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDefaultConfig

Returns a new instance of DefaultConfig.



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

def initialize
  self.env = {
    'ANSIBLE_FORCE_COLOR' => 'True',
    'ANSIBLE_HOST_KEY_CHECKING' => 'False'
  }

  self.params = {
    debug: false
  }

  # options
  self.extra_vars = {
    # skip creation of .retry files
    'retry_files_enabled' => 'False'
  }
  # TODO support --ssh-common-args, --ssh-extra-args
  # e.g. ansible-playbook --ssh-common-args="-o ServerAliveInterval=60" -i inventory install.yml
end

Instance Attribute Details

#envObject

Returns the value of attribute env

Returns:

  • (Object)

    the current value of env



8
9
10
# File 'lib/ansible/config.rb', line 8

def env
  @env
end

#extra_varsObject

Returns the value of attribute extra_vars

Returns:

  • (Object)

    the current value of extra_vars



8
9
10
# File 'lib/ansible/config.rb', line 8

def extra_vars
  @extra_vars
end

#paramsObject

Returns the value of attribute params

Returns:

  • (Object)

    the current value of params



8
9
10
# File 'lib/ansible/config.rb', line 8

def params
  @params
end

Instance Method Details

#optionsObject

NB: –extra-vars can also accept JSON string, see stackoverflow.com/questions/25617273/pass-array-in-extra-vars-ansible



29
30
31
32
33
34
# File 'lib/ansible/config.rb', line 29

def options
  x = extra_vars.each_with_object('--extra-vars=\'') { |kv, a| a << "#{kv.first}=\"#{kv.last}\" " }.strip+'\'' if extra_vars unless extra_vars.empty?
  # can test with configure { |config| config.extra_vars.clear }

  [x, '--ssh-extra-args=\'-o UserKnownHostsFile=/dev/null\'']*' '
end

#to_s(cmd) ⇒ Object



36
37
38
39
40
# File 'lib/ansible/config.rb', line 36

def to_s(cmd)
  entire_cmd = [env.each_with_object([]) { |kv, a| a << kv*'=' } * ' ', cmd, options]*' '
  puts entire_cmd if params[:debug]
  entire_cmd
end