Class: Ansible::Config::DefaultConfig
- Inherits:
-
Struct
- Object
- Struct
- Ansible::Config::DefaultConfig
- Defined in:
- lib/ansible/config.rb
Overview
Default configuration options
Instance Attribute Summary collapse
-
#env ⇒ Hash
Environment variables.
-
#extra_vars ⇒ Hash
Extra variables to pass to Ansible.
-
#params ⇒ Hash
Parameters.
Instance Method Summary collapse
-
#initialize ⇒ DefaultConfig
constructor
A new instance of DefaultConfig.
-
#options ⇒ String
Pass additional options to Ansible NB: –extra-vars can also accept JSON string, see stackoverflow.com/questions/25617273/pass-array-in-extra-vars-ansible.
-
#to_s(cmd) ⇒ Config, DefaultConfig
Output configuration as a string for the command-line.
Constructor Details
#initialize ⇒ DefaultConfig
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
#env ⇒ Hash
Returns environment variables.
10 11 12 |
# File 'lib/ansible/config.rb', line 10 def env @env end |
#extra_vars ⇒ Hash
Returns extra variables to pass to Ansible.
10 11 12 |
# File 'lib/ansible/config.rb', line 10 def extra_vars @extra_vars end |
#params ⇒ Hash
Returns parameters.
10 11 12 |
# File 'lib/ansible/config.rb', line 10 def params @params end |
Instance Method Details
#options ⇒ String
Pass additional options to Ansible NB: –extra-vars can also accept JSON string, see stackoverflow.com/questions/25617273/pass-array-in-extra-vars-ansible
39 40 41 42 43 44 |
# File 'lib/ansible/config.rb', line 39 def 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
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, ]*' ' puts entire_cmd if params[:debug] entire_cmd end |