]> git.immae.eu Git - perso/Immae/Projets/Puppet.git/blobdiff - modules/base_installation/lib/puppet/functions/ldap_data.rb
Order ldap configuration by priority
[perso/Immae/Projets/Puppet.git] / modules / base_installation / lib / puppet / functions / ldap_data.rb
index ff8d7794ad964a0fd1fd869c0b504a1e3de4a9f8..0a6d9356af1b695b57dfefa5e0c2d4445d43a1eb 100644 (file)
@@ -10,7 +10,7 @@ Puppet::Functions.create_function(:ldap_data) do
     begin
       require 'ldap'
       require 'puppet/util/ldap/connection'
-    rescue
+    rescue LoadError
       context.not_found
       return
     end
@@ -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