From 2ec6746cf2564470f514319cb73c36d867be4078 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Bouya?= Date: Tue, 26 Jun 2018 00:39:14 +0200 Subject: Cleanup backup hosts information lookup --- .../lib/puppet/parser/functions/find_host.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 modules/base_installation/lib/puppet/parser/functions/find_host.rb (limited to 'modules/base_installation') diff --git a/modules/base_installation/lib/puppet/parser/functions/find_host.rb b/modules/base_installation/lib/puppet/parser/functions/find_host.rb new file mode 100644 index 0000000..79aae5c --- /dev/null +++ b/modules/base_installation/lib/puppet/parser/functions/find_host.rb @@ -0,0 +1,18 @@ +module Puppet::Parser::Functions + newfunction(:find_host, :type => :rvalue, :doc => <<-EOS +This function searches through the hosts to find the one with matching cn + EOS + ) do |arguments| + + if (arguments.size != 2) then + raise(Puppet::ParseError, "grep(): Wrong number of arguments given #{arguments.size} for 2") + end + + hosts = arguments[0] + cn = arguments[1] + + hosts.find { |host| host["cn"].any? { |cn_| cn_ == cn } } + end +end + +# vim: set ts=2 sw=2 et : -- cgit v1.2.3