From: Ismaƫl Bouya Date: Tue, 5 Jun 2018 18:54:18 +0000 (+0200) Subject: Order ldap configuration by priority X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=435b97f50bdc1c8a5e48bedf3772fcb16abb3440;p=perso%2FImmae%2FProjets%2FPuppet.git Order ldap configuration by priority --- 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