Guest User

Untitled

a guest
Jun 17th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. require 'faster_csv'
  2.  
  3.  
  4. module Puppet::Parser::Functions
  5. newfunction(:csvlookup, :type => :rvalue) do |args|
  6. csvfile = "/etc/puppet/lookup.csv"
  7.  
  8. key = args[0]
  9. fieldnum = args[1]
  10. csvfile = args[2] if args[2]
  11. result = nil
  12. if File.exists?(csvfile)
  13. parser.watch_file(csvfile)
  14.  
  15. FasterCSV.foreach(csvfile, :headers => true) do |row|
  16. if row[0] == key
  17. result = row[fieldnum]
  18. end
  19. end
  20. end
  21. result
  22. end
  23. end
Add Comment
Please, Sign In to add comment