Module: Inventory

Defined in:
lib/serverspec-runner/ansible/inventory.rb

Class Method Summary collapse

Class Method Details

.inventory_to_platform(data) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/serverspec-runner/ansible/inventory.rb', line 2

def self.inventory_to_platform(data)
  platform = {}

  data.each do |k, v|
    v.each do |gk, gv|
      if gk == 'hosts'
        if gv.kind_of?(Hash)
          gv.each do |hk, hv|
            platform[hk.to_sym] = unless hv.nil?
                             convert_ssh_opt(v['vars']).merge(convert_ssh_opt(hv))
                           else
                             convert_ssh_opt(v['vars'])
                           end
          end
        elsif gv.kind_of?(Array)
          gv.each do |h|
            platform[h.to_sym] = convert_ssh_opt(v['vars'])
          end
        end
      end
    end
  end

  platform
end