From 435b97f50bdc1c8a5e48bedf3772fcb16abb3440 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Isma=C3=ABl=20Bouya?= Date: Tue, 5 Jun 2018 20:54:18 +0200 Subject: [PATCH] Order ldap configuration by priority --- .../lib/puppet/functions/ldap_data.rb | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/modules/base_installation/lib/puppet/functions/ldap_data.rb b/modules/base_installation/lib/puppet/functions/ldap_data.rb index 0c92d89..0a6d935 100644 --- a/modules/base_installation/lib/puppet/functions/ldap_data.rb +++ b/modules/base_installation/lib/puppet/functions/ldap_data.rb @@ -30,9 +30,19 @@ Puppet::Functions.create_function(:ldap_data) do filter = "(objectclass=*)" data = {} - connection.search(base, scope, filter) do |entry| - data_ = entry.to_hash - jsons = data_["immaePuppetJson"] || [] + data_array = connection.search2(base, scope, filter, attrs=["immaePuppetJson", "dn"]).map do |entry| + [entry["dn"].first, entry["immaePuppetJson"] || []] + end.sort_by do |dn, json| + if dn == "ou=roles,ou=hosts,dc=immae,dc=eu" + [0, dn] + elsif dn.end_with?("ou=roles,ou=hosts,dc=immae,dc=eu") + [1, dn] + else + [2, dn] + end + end.to_h + + data_array.each do |dn, jsons| jsons.each do |json| data.merge!(JSON.parse(json)) end -- 2.41.0