Class: Ansible::Config::DefaultConfig

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

Overview

Default configuration options

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDefaultConfig

Returns a new instance of DefaultConfig.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/ansible/config.rb', line 18

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

  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

  self.params = {
    debug: false
  }
end

Instance Attribute Details

#envHash

Returns environment variables.

Returns:

  • (Hash)

    environment variables



10
11
12
# File 'lib/ansible/config.rb', line 10

def env
  @env
end

#extra_varsHash

Returns extra variables to pass to Ansible.

Returns:

  • (Hash)

    extra variables to pass to Ansible



10
11
12
# File 'lib/ansible/config.rb', line 10

def extra_vars
  @extra_vars
end

#paramsHash

Returns parameters.

Returns:

  • (Hash)

    parameters



10
11
12
# File 'lib/ansible/config.rb', line 10

def params
  @params
end

Instance Method Details

#optionsString

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

Returns:

  • (String)

    command-line options



39
40
41
42
43
44
# File 'lib/ansible/config.rb', line 39

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) ⇒ Config, DefaultConfig

Output configuration as a string for the command-line

Parameters:

  • cmd (String)

    command to be appended to the command-line produced

Returns:



49
50
51
52
53
# File 'lib/ansible/config.rb', line 49

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