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 read_yaml = lambda { |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
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)
46 yaml = YAML.load_file(yamlfile)
50 Dir.entries('/var/lib/puppet/yaml/node/').each do |fname|
51 next unless fname =~ /(.*)\.yaml$/
53 ret[host_name] = read_yaml.call(yaml, host_name)
56 ret = read_yaml.call(yaml, host)