Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'faster_csv'
- module Puppet::Parser::Functions
- newfunction(:csvlookup, :type => :rvalue) do |args|
- csvfile = "/etc/puppet/lookup.csv"
- key = args[0]
- fieldnum = args[1]
- csvfile = args[2] if args[2]
- result = nil
- if File.exists?(csvfile)
- parser.watch_file(csvfile)
- FasterCSV.foreach(csvfile, :headers => true) do |row|
- if row[0] == key
- result = row[fieldnum]
- end
- end
- end
- result
- end
- end
Add Comment
Please, Sign In to add comment