1 module Puppet::Parser::Functions
2 newfunction(:yamlinfo, :type => :rvalue) do |args|
6 parser = Puppet::Parser::Parser.new(environment)
7 parser.watch_file(yamlfile)
9 def read_yaml(yaml, host)
12 ['nameinfo', 'footer'].each do |detail|
13 if yaml.has_key?(detail)
14 if yaml[detail].has_key?(host)
15 results[detail] = yaml[detail][host]
20 if yaml.has_key?('services')
21 yaml['services'].each_pair do |service, hostlist|
22 hostlist=[hostlist] unless hostlist.kind_of?(Array)
23 results[service] = hostlist.include?(host)
27 results['mail_port'] = ''
28 results['smarthost'] = ''
29 results['heavy_exim'] = ''
30 results['smarthost_port'] = 587
31 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'
33 if yaml['host_settings'].kind_of?(Hash)
34 yaml['host_settings'].each_pair do |property, values|
35 if values.kind_of?(Hash)
36 results[property] = values[host] if values.has_key?(host)
37 elsif values.kind_of?(Array)
38 results[property] = values.include?(host)
48 yaml = YAML.load_file(yamlfile)
52 Dir.entries('/var/lib/puppet/yaml/node/').each do |fname|
53 next unless fname =~ /(.*)\.yaml$/
55 ret[host_name] = read_yaml(yaml, host_name)
58 ret = read_yaml(yaml, host)