diff options
author | Ismaël Bouya <ismael.bouya@normalesup.org> | 2017-09-17 19:05:41 +0200 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@normalesup.org> | 2017-09-18 00:22:19 +0200 |
commit | 248bd83ed797f6e0f385e72a56aa7bafdf23d490 (patch) | |
tree | 29cd0d69b73b34d6d12ebe354be9d1d616983e3f /modules/base_installation/lib | |
parent | 503e4cf5c54e3fe4b802038e8917341c4ce803e5 (diff) | |
download | Puppet-248bd83ed797f6e0f385e72a56aa7bafdf23d490.tar.gz Puppet-248bd83ed797f6e0f385e72a56aa7bafdf23d490.tar.zst Puppet-248bd83ed797f6e0f385e72a56aa7bafdf23d490.zip |
Enhance install script, and add ip6 address
Diffstat (limited to 'modules/base_installation/lib')
-rw-r--r-- | modules/base_installation/lib/facter/ldapvar.rb | 83 |
1 files changed, 43 insertions, 40 deletions
diff --git a/modules/base_installation/lib/facter/ldapvar.rb b/modules/base_installation/lib/facter/ldapvar.rb index ff8e898..3ee6623 100644 --- a/modules/base_installation/lib/facter/ldapvar.rb +++ b/modules/base_installation/lib/facter/ldapvar.rb | |||
@@ -1,46 +1,49 @@ | |||
1 | require 'ldap' | 1 | begin |
2 | require 'puppet/util/ldap/connection' | 2 | require 'ldap' |
3 | 3 | require 'puppet/util/ldap/connection' | |
4 | Facter.add("ldapvar") do | 4 | |
5 | setcode do | 5 | Facter.add("ldapvar") do |
6 | if Puppet[:node_terminus].to_sym != :ldap | 6 | setcode do |
7 | data = [] | 7 | if Puppet[:node_terminus].to_sym != :ldap |
8 | else | 8 | data = [] |
9 | begin | 9 | else |
10 | conn = Puppet::Util::Ldap::Connection.instance | 10 | begin |
11 | conn.start | 11 | conn = Puppet::Util::Ldap::Connection.instance |
12 | connection = conn.connection | 12 | conn.start |
13 | rescue ::LDAP::ResultError => e | 13 | connection = conn.connection |
14 | raise Puppet::ParseError, ("ldapquery(): LDAP ResultError - #{e.message}") | 14 | rescue ::LDAP::ResultError => e |
15 | end | 15 | raise Puppet::ParseError, ("ldapquery(): LDAP ResultError - #{e.message}") |
16 | 16 | end | |
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 | 17 | ||
37 | if data_["cn"].any? { |cn| cn == host } | 18 | host = Facter.value('ec2_metadata')["hostname"] |
38 | data[:self] = data_ | 19 | base = Puppet[:ldapbase] |
20 | scope = ::LDAP::LDAP_SCOPE_SUBTREE | ||
21 | filter = "(objectclass=*)" | ||
22 | |||
23 | data = { | ||
24 | :self => {}, | ||
25 | :other => [], | ||
26 | } | ||
27 | |||
28 | connection.search(base, scope, filter) do |entry| | ||
29 | data_ = entry.to_hash | ||
30 | data_['vars'] = (data_[Puppet[:ldapstackedattrs]] || []) | ||
31 | .map { |var| var.split("=", 2) } | ||
32 | .group_by { |(key, value)| key } | ||
33 | .map { |key, value| [key, value.map(&:last)] } | ||
34 | .to_h | ||
35 | |||
36 | data[:other] << data_ | ||
37 | |||
38 | if data_["cn"].any? { |cn| cn == host } | ||
39 | data[:self] = data_ | ||
40 | end | ||
39 | end | 41 | end |
40 | end | ||
41 | 42 | ||
42 | data | 43 | data |
44 | end | ||
43 | end | 45 | end |
44 | end | 46 | end |
47 | rescue LoadError | ||
48 | # No facts | ||
45 | end | 49 | end |
46 | |||