From 4921ab7b2bc850505988c8137b35b86269e52c09 Mon Sep 17 00:00:00 2001 From: Peter Palfrader Date: Thu, 28 Jul 2016 20:32:22 +0000 Subject: [PATCH] move to stringifying our facts again --- .../debian-org/lib/facter/onion-services.rb | 28 +++++++++++-------- .../puppet/parser/functions/onion_hostname.rb | 14 ++++++++++ 2 files changed, 31 insertions(+), 11 deletions(-) create mode 100644 modules/puppetmaster/lib/puppet/parser/functions/onion_hostname.rb 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: -- 2.20.1