From: Peter Palfrader Date: Thu, 28 Jul 2016 20:32:22 +0000 (+0000) Subject: move to stringifying our facts again X-Git-Url: https://git.adam-barratt.org.uk/?a=commitdiff_plain;h=4921ab7b2bc850505988c8137b35b86269e52c09;p=mirror%2Fdsa-puppet.git move to stringifying our facts again --- diff --git a/modules/debian-org/lib/facter/onion-services.rb b/modules/debian-org/lib/facter/onion-services.rb index 08aa1349a..5e3998feb 100644 --- a/modules/debian-org/lib/facter/onion-services.rb +++ b/modules/debian-org/lib/facter/onion-services.rb @@ -1,13 +1,19 @@ -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 diff --git a/modules/puppetmaster/lib/puppet/parser/functions/onion_hostname.rb b/modules/puppetmaster/lib/puppet/parser/functions/onion_hostname.rb new file mode 100644 index 000000000..b0d15a615 --- /dev/null +++ b/modules/puppetmaster/lib/puppet/parser/functions/onion_hostname.rb @@ -0,0 +1,14 @@ +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: