Class: BarkingIguana::Compound::Ansible::Inventory

Inherits:
Object
  • Object
show all
Defined in:
lib/barking_iguana/compound/ansible/inventory.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Inventory

Returns a new instance of Inventory.



8
9
10
# File 'lib/barking_iguana/compound/ansible/inventory.rb', line 8

def initialize path
  self.path = path
end

Instance Attribute Details

#pathObject

Returns the value of attribute path.



5
6
7
# File 'lib/barking_iguana/compound/ansible/inventory.rb', line 5

def path
  @path
end

Instance Method Details

#hostgroupsObject



12
13
14
15
16
17
18
# File 'lib/barking_iguana/compound/ansible/inventory.rb', line 12

def hostgroups
  hg = InventoryParser.load_targets path
  hg.reject! do |k,v|
    k =~ /:vars$/
  end
  hg
end

#hostsObject



20
21
22
23
24
25
26
# File 'lib/barking_iguana/compound/ansible/inventory.rb', line 20

def hosts
  hosts = hostgroups.values.flatten.compact.uniq { |h| h['uri'] }
  hosts.map do |data|
    name = data['name'].gsub(/ .*/, '')
    Host.new name: name, ip_address: data['uri']
  end
end