aboutsummaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@normalesup.org>2017-09-10 11:26:18 +0200
committerIsmaël Bouya <ismael.bouya@normalesup.org>2017-09-10 12:10:21 +0200
commit945ae444952f3322c4687059f0ba6b7308750feb (patch)
tree0774bfe30fb0da9f001d621b86dbc34d16ff8393 /modules
parentec1096d8c0d897ebd1ea445d9c5404a13c33ce2e (diff)
downloadPuppet-945ae444952f3322c4687059f0ba6b7308750feb.tar.gz
Puppet-945ae444952f3322c4687059f0ba6b7308750feb.tar.zst
Puppet-945ae444952f3322c4687059f0ba6b7308750feb.zip
ldapvar facter
Diffstat (limited to 'modules')
-rw-r--r--modules/base_installation/lib/facter/ldapvar.rb46
1 files changed, 46 insertions, 0 deletions
diff --git a/modules/base_installation/lib/facter/ldapvar.rb b/modules/base_installation/lib/facter/ldapvar.rb
new file mode 100644
index 0000000..ff8e898
--- /dev/null
+++ b/modules/base_installation/lib/facter/ldapvar.rb
@@ -0,0 +1,46 @@
1require 'ldap'
2require 'puppet/util/ldap/connection'
3
4Facter.add("ldapvar") do
5 setcode do
6 if Puppet[:node_terminus].to_sym != :ldap
7 data = []
8 else
9 begin
10 conn = Puppet::Util::Ldap::Connection.instance
11 conn.start
12 connection = conn.connection
13 rescue ::LDAP::ResultError => e
14 raise Puppet::ParseError, ("ldapquery(): LDAP ResultError - #{e.message}")
15 end
16
17 host = Facter.value('ec2_metadata')["hostname"]
18 base = Puppet[:ldapbase]
19 scope = ::LDAP::LDAP_SCOPE_SUBTREE
20 filter = "(objectclass=*)"
21
22 data = {
23 :self => {},
24 :other => [],
25 }
26
27 connection.search(base, scope, filter) do |entry|
28 data_ = entry.to_hash
29 data_['vars'] = (data_[Puppet[:ldapstackedattrs]] || [])
30 .map { |var| var.split("=", 2) }
31 .group_by { |(key, value)| key }
32 .map { |key, value| [key, value.map(&:last)] }
33 .to_h
34
35 data[:other] << data_
36
37 if data_["cn"].any? { |cn| cn == host }
38 data[:self] = data_
39 end
40 end
41
42 data
43 end
44 end
45end
46