1 module Puppet::Parser::Functions
2 newfunction(:yamlinfo, :type => :rvalue) do |args|
6 parser.watch_file(yamlfile)
8 def read_yaml(yaml, host)
11 ['nameinfo', 'footer'].each do |detail|
12 if yaml.has_key?(detail)
13 if yaml[detail].has_key?(host)
14 results[detail] = yaml[detail][host]
19 if yaml.has_key?('services')
20 yaml['services'].each_pair do |service, hostlist|
21 hostlist=[hostlist] unless hostlist.kind_of?(Array)
22 results[service] = hostlist.include?(host)
26 results['mail_port'] = ''
27 results['smarthost'] = ''
28 results['heavy_exim'] = ''
29 results['smarthost_port'] = 587
30 results['reservedaddrs'] = '0.0.0.0/8 : 127.0.0.0/8 : 10.0.0.0/8 : 169.254.0.0/16 : 172.16.0.0/12 : 192.0.0.0/17 : 192.168.0.0/16 : 224.0.0.0/4 : 240.0.0.0/5 : 248.0.0.0/5'
32 if yaml['host_settings'].kind_of?(Hash)
33 yaml['host_settings'].each_pair do |property, values|
34 if values.kind_of?(Hash)
35 results[property] = values[host] if values.has_key?(host)
36 elsif values.kind_of?(Array)
37 results[property] = values.include?(host)
47 yaml = YAML.load_file(yamlfile)
51 Dir.entries('/var/lib/puppet/yaml/node/').each do |fname|
52 next unless fname =~ /(.*)\.yaml$/
54 ret[host_name] = read_yaml(yaml, host_name)
57 ret = read_yaml(yaml, host)