Top Level Namespace

Defined Under Namespace

Classes: Chef_Solo_Nodes

Instance Method Summary collapse

Instance Method Details

#Chef_Solo_IPs(*args) ⇒ Object

Arguments:

  Same as Chef_Solo_Nodes()

Returns:

  Array of Strings.


42
43
44
45
46
47
48
49
50
51
52
# File 'lib/Chef_Solo_Nodes.rb', line 42

def Chef_Solo_IPs *args
  Chef_Solo_Nodes(*args).map { |h| 
    u = h['user'] || h['login']
    a = h['ipaddress'] || h['hostname'] 
    p = h['port'] 

    final = [u, a].compact.join('@')
    final = [final, p].compact.join(':')
    final
  }
end

#Chef_Solo_Nodes(role_or_paths = '*') ⇒ Object

Arguments:

  role_or_paths = File paths Array OR Role name String.

Returns:

  Array of Hashes.


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/Chef_Solo_Nodes.rb', line 14

def Chef_Solo_Nodes role_or_paths = '*'
  
  if role_or_paths.is_a?(Array)
    role = '*'
    files = role_or_paths.map { |path| File.expand_path(path) }
  else
    role = role_or_paths.to_s
    files = Dir.glob("nodes/*.json")
  end
  
  files.map { |str| 
    h = JSON(File.read(str))
    next if role != '*' && !(h['roles'] || []).include?(role)
    h['ipaddress'] ||= File.basename(str).sub(".json", "")
    h
  }.compact
  
end