aboutsummaryrefslogtreecommitdiff
path: root/modules/base_installation
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@normalesup.org>2017-09-17 19:05:41 +0200
committerIsmaël Bouya <ismael.bouya@normalesup.org>2017-09-18 00:22:19 +0200
commit248bd83ed797f6e0f385e72a56aa7bafdf23d490 (patch)
tree29cd0d69b73b34d6d12ebe354be9d1d616983e3f /modules/base_installation
parent503e4cf5c54e3fe4b802038e8917341c4ce803e5 (diff)
downloadPuppet-248bd83ed797f6e0f385e72a56aa7bafdf23d490.tar.gz
Puppet-248bd83ed797f6e0f385e72a56aa7bafdf23d490.tar.zst
Puppet-248bd83ed797f6e0f385e72a56aa7bafdf23d490.zip
Enhance install script, and add ip6 address
Diffstat (limited to 'modules/base_installation')
-rw-r--r--modules/base_installation/files/services/en-dhcp.network8
-rw-r--r--modules/base_installation/lib/facter/ldapvar.rb83
-rw-r--r--modules/base_installation/manifests/services.pp13
-rw-r--r--modules/base_installation/templates/services/en-dhcp.network.erb13
4 files changed, 63 insertions, 54 deletions
diff --git a/modules/base_installation/files/services/en-dhcp.network b/modules/base_installation/files/services/en-dhcp.network
deleted file mode 100644
index 6eef0e9..0000000
--- a/modules/base_installation/files/services/en-dhcp.network
+++ /dev/null
@@ -1,8 +0,0 @@
1[Match]
2Name=en*
3
4[Network]
5DHCP=yes
6
7[DHCP]
8UseMTU=true
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 @@
1require 'ldap' 1begin
2require 'puppet/util/ldap/connection' 2 require 'ldap'
3 3 require 'puppet/util/ldap/connection'
4Facter.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
47rescue LoadError
48 # No facts
45end 49end
46
diff --git a/modules/base_installation/manifests/services.pp b/modules/base_installation/manifests/services.pp
index b48c3b5..c641f4b 100644
--- a/modules/base_installation/manifests/services.pp
+++ b/modules/base_installation/manifests/services.pp
@@ -38,13 +38,14 @@ class base_installation::services inherits base_installation {
38 group => "root" 38 group => "root"
39 } 39 }
40 40
41 $ip6 = lookup("ips.v6") |$key| { {} }
41 file { '/etc/systemd/network/en-dhcp.network': 42 file { '/etc/systemd/network/en-dhcp.network':
42 ensure => "present", 43 ensure => "present",
43 path => "/etc/systemd/network/en-dhcp.network", 44 path => "/etc/systemd/network/en-dhcp.network",
44 source => 'puppet:///modules/base_installation/services/en-dhcp.network', 45 content => template('base_installation/services/en-dhcp.network.erb'),
45 mode => "0644", 46 mode => "0644",
46 owner => "root", 47 owner => "root",
47 group => "root" 48 group => "root"
48 } 49 }
49 50
50} 51}
diff --git a/modules/base_installation/templates/services/en-dhcp.network.erb b/modules/base_installation/templates/services/en-dhcp.network.erb
new file mode 100644
index 0000000..4f55582
--- /dev/null
+++ b/modules/base_installation/templates/services/en-dhcp.network.erb
@@ -0,0 +1,13 @@
1[Match]
2Name=en*
3
4[Network]
5DHCP=ipv4
6
7<%- unless @ip6.empty? -%>
8Address=<%= @ip6["ipAddress"] %>/<%= @ip6["mask"] %>
9Gateway=<%= @ip6["gateway"] %>
10<%- end -%>
11
12[DHCP]
13UseMTU=true