]>
git.immae.eu Git - perso/Immae/Projets/Puppet.git/blob - modules/base_installation/lib/puppet/functions/ldap_data.rb
3 Puppet
::Functions.create_function(:ldap_data) do
6 param
'Puppet::LookupContext', :context
9 def ldap_data(options
, context
)
12 require 'puppet/util/ldap/connection'
18 if !context
.cache_has_key("ldap_lookup")
20 conn
= Puppet
::Util::Ldap::Connection.instance
22 connection
= conn
.connection
23 rescue ::LDAP::ResultError => e
24 raise Puppet
::ParseError, ("ldapquery(): LDAP ResultError - #{e.message}")
27 host
= Facter
.value('ec2_metadata')["hostname"]
28 base
= Puppet
[:ldapbase]
29 scope
= ::LDAP::LDAP_SCOPE_SUBTREE
30 filter
= "(objectclass=*)"
33 connection
.search(base
, scope
, filter
) do |entry
|
35 jsons
= data_
["immaePuppetJson"] || []
37 data.merge!
(JSON
.parse(json
))
41 context
.cache("ldap_lookup", data)
44 context
.cached_value("ldap_lookup")