1 module Puppet::Parser::Functions
2 newfunction(:yamlinfo, :type => :rvalue) do |args|
7 read_yaml = lambda { |yaml, host|
10 ['nameinfo', 'footer'].each do |detail|
11 if yaml.has_key?(detail)
12 if yaml[detail].has_key?(host)
13 results[detail] = yaml[detail][host]
18 if yaml.has_key?('services')
19 yaml['services'].each_pair do |service, hostlist|
20 hostlist=[hostlist] unless hostlist.kind_of?(Array)
21 results[service] = hostlist.include?(host)
25 results['mail_port'] = ''
26 results['smarthost'] = ''
27 results['heavy_exim'] = ''
28 results['smarthost_port'] = 587
30 if yaml['host_settings'].kind_of?(Hash)
31 yaml['host_settings'].each_pair do |property, values|
32 if values.kind_of?(Hash)
33 results[property] = values[host] if values.has_key?(host)
34 elsif values.kind_of?(Array)
35 results[property] = values.include?(host)
44 yaml = YAML.load_file(yamlfile)
48 Dir.entries('/var/lib/puppet/yaml/node/').each do |fname|
49 next unless fname =~ /(.*)\.yaml$/
51 ret[host_name] = read_yaml.call(yaml, host_name)
54 ret = read_yaml.call(yaml, host)