]> git.immae.eu Git - perso/Immae/Projets/Puppet.git/blobdiff - modules/base_installation/lib/puppet/parser/functions/find_host.rb
Cleanup backup hosts information lookup
[perso/Immae/Projets/Puppet.git] / modules / base_installation / lib / puppet / parser / functions / find_host.rb
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 (file)
index 0000000..79aae5c
--- /dev/null
@@ -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 :