1 require 'puppet/file_system'
3 module Puppet::Parser::Functions
4 newfunction(:yamlinfo, :type => :rvalue) do |args|
8 read_yaml = lambda { |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
31 if yaml['host_settings'].kind_of?(Hash)
32 yaml['host_settings'].each_pair do |property, values|
33 if values.kind_of?(Hash)
34 results[property] = values[host] if values.has_key?(host)
35 elsif values.kind_of?(Array)
36 results[property] = values.include?(host)
45 yamlfile = Puppet::Parser::Files.find_file('debian_org/misc/local.yaml', compiler.environment)
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)