From: Ismaƫl Bouya Date: Mon, 25 Jun 2018 22:39:14 +0000 (+0200) Subject: Cleanup backup hosts information lookup X-Git-Url: https://git.immae.eu/?p=perso%2FImmae%2FProjets%2FPuppet.git;a=commitdiff_plain;h=2ec6746cf2564470f514319cb73c36d867be4078 Cleanup backup hosts information lookup --- 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 : diff --git a/modules/role/manifests/backup/postgresql.pp b/modules/role/manifests/backup/postgresql.pp index e891195..b26773c 100644 --- a/modules/role/manifests/backup/postgresql.pp +++ b/modules/role/manifests/backup/postgresql.pp @@ -94,7 +94,15 @@ class role::backup::postgresql inherits role::backup { } } - $pg_backup_hosts.each |$pg_backup_host, $pg_infos| { + $pg_backup_hosts.each |$backup_host_cn, $pg_infos| { + $host = find_host($facts["ldapvar"]["other"], $backup_host_cn) + if empty($host) { + $pg_backup_host = $backup_host_cn + } elsif has_key($host["vars"], "host") { + $pg_backup_host = $host["vars"]["host"][0] + } else { + $pg_backup_host = $host["vars"]["real_hostname"][0] + } $pg_path = "$mountpoint/$pg_backup_host/postgresql" $pg_backup_path = "$mountpoint/$pg_backup_host/postgresql_backup" $pg_host = "$pg_backup_host"