Class: AnsibleSpec::AnsibleCfg
- Inherits:
-
Object
- Object
- AnsibleSpec::AnsibleCfg
- Defined in:
- lib/ansible_spec/load_ansible.rb
Class Method Summary collapse
- .find_ansible_cfgs ⇒ Object
-
.load_ansible_cfg ⇒ Object
return : Hash.
Instance Method Summary collapse
- #get(section, key) ⇒ Object
-
#initialize ⇒ AnsibleCfg
constructor
A new instance of AnsibleCfg.
- #roles_path ⇒ Object
Constructor Details
#initialize ⇒ AnsibleCfg
Returns a new instance of AnsibleCfg.
600 601 602 |
# File 'lib/ansible_spec/load_ansible.rb', line 600 def initialize @cfg = self.class.load_ansible_cfg end |
Class Method Details
.find_ansible_cfgs ⇒ Object
610 611 612 613 614 615 616 617 618 619 |
# File 'lib/ansible_spec/load_ansible.rb', line 610 def find_ansible_cfgs() files = [] ["/etc/ansible/ansible.cfg", File.("~/.ansible.cfg"), "./ansible.cfg", ENV["ANSIBLE_CFG"], ].each do |f| files << f if f and File.exist? f end end |
.load_ansible_cfg ⇒ Object
return : Hash
622 623 624 625 626 627 628 629 630 |
# File 'lib/ansible_spec/load_ansible.rb', line 622 def load_ansible_cfg() cfg_hash = {} self.find_ansible_cfgs.each do |file| cfg_file = IniFile.new :filename => file # Merge without calling tainted? method cfg_hash.merge!(cfg_file.to_h) end cfg_hash # return Hash end |
Instance Method Details
#get(section, key) ⇒ Object
633 634 635 636 637 638 639 640 |
# File 'lib/ansible_spec/load_ansible.rb', line 633 def get(section, key) s = @cfg[section] if s return s[key] else return nil end end |
#roles_path ⇒ Object
604 605 606 607 |
# File 'lib/ansible_spec/load_ansible.rb', line 604 def roles_path rp = (self.get('defaults', 'roles_path') or '').split(':') rp << 'roles' # Roles is always searched end |