Class: AnsibleSpec::AnsibleCfg

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAnsibleCfg

Returns a new instance of AnsibleCfg.



584
585
586
# File 'lib/ansible_spec/load_ansible.rb', line 584

def initialize
  @cfg = self.class.load_ansible_cfg
end

Class Method Details

.find_ansible_cfgsObject



594
595
596
597
598
599
600
601
602
603
# File 'lib/ansible_spec/load_ansible.rb', line 594

def find_ansible_cfgs()
  files = []
  ["/etc/ansible/ansible.cfg",
   File.expand_path("~/.ansible.cfg"),
   "./ansible.cfg",
   ENV["ANSIBLE_CFG"],
  ].each do |f|
    files << f if f and File.exists? f
  end
end

.load_ansible_cfgObject



605
606
607
608
609
610
611
# File 'lib/ansible_spec/load_ansible.rb', line 605

def load_ansible_cfg()
  cfg = IniFile.new
  self.find_ansible_cfgs.each do |file|
    cfg = cfg.merge(IniFile.new :filename => file)
  end
  cfg.to_h
end

Instance Method Details

#get(section, key) ⇒ Object



614
615
616
617
618
619
620
621
# File 'lib/ansible_spec/load_ansible.rb', line 614

def get(section, key)
  s = @cfg[section]
  if s
    return s[key]
  else
    return nil
  end
end

#roles_pathObject



588
589
590
591
# File 'lib/ansible_spec/load_ansible.rb', line 588

def roles_path
  rp = (self.get('defaults', 'roles_path') or '').split(':')
  rp << 'roles'  # Roles is always searched
end