-Facter.add("onion_hostname") do
- services = {}
+begin
+ require 'json'
- Dir['/var/lib/tor/onion/*/hostname'].each do |p|
- dir = File.dirname(p)
- service = File.basename(dir)
- hostname = IO.read(p).chomp
- services[service] = hostname
- end
- setcode do
- services
- end
+ Facter.add("onion_hostname") do
+ services = {}
+
+ Dir['/var/lib/tor/onion/*/hostname'].each do |p|
+ dir = File.dirname(p)
+ service = File.basename(dir)
+ hostname = IO.read(p).chomp
+ services[service] = hostname
+ end
+ setcode do
+ services.to_json
+ end
+ end
+
+rescue Exception => e
end
--- /dev/null
+module Puppet::Parser::Functions
+ newfunction(:onion_hostname, :type => :rvalue) do |args|
+ servicename = args.shift()
+
+ onion_hostname_fact = lookupvar('onion_hostname')
+
+ require 'json'
+ parsed = JSON.parse(onion_hostname_fact)
+ return parsed[servicename]
+ end
+end
+# vim:set ts=2:
+# vim:set et:
+# vim:set shiftwidth=2: