diff options
author | Ismaël Bouya <ismael.bouya@normalesup.org> | 2018-06-26 00:39:14 +0200 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@normalesup.org> | 2018-06-26 00:44:53 +0200 |
commit | 2ec6746cf2564470f514319cb73c36d867be4078 (patch) | |
tree | 68925142ed37ef3ec33c7494bf43420d4e58dc32 /modules/base_installation/lib | |
parent | d60467e093d6cf1170a9cbbc5c03b80b8ec1da4a (diff) | |
download | Puppet-2ec6746cf2564470f514319cb73c36d867be4078.tar.gz Puppet-2ec6746cf2564470f514319cb73c36d867be4078.tar.zst Puppet-2ec6746cf2564470f514319cb73c36d867be4078.zip |
Cleanup backup hosts information lookup
Diffstat (limited to 'modules/base_installation/lib')
-rw-r--r-- | modules/base_installation/lib/puppet/parser/functions/find_host.rb | 18 |
1 files changed, 18 insertions, 0 deletions
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 @@ | |||
1 | module Puppet::Parser::Functions | ||
2 | newfunction(:find_host, :type => :rvalue, :doc => <<-EOS | ||
3 | This function searches through the hosts to find the one with matching cn | ||
4 | EOS | ||
5 | ) do |arguments| | ||
6 | |||
7 | if (arguments.size != 2) then | ||
8 | raise(Puppet::ParseError, "grep(): Wrong number of arguments given #{arguments.size} for 2") | ||
9 | end | ||
10 | |||
11 | hosts = arguments[0] | ||
12 | cn = arguments[1] | ||
13 | |||
14 | hosts.find { |host| host["cn"].any? { |cn_| cn_ == cn } } | ||
15 | end | ||
16 | end | ||
17 | |||
18 | # vim: set ts=2 sw=2 et : | ||