From 248bd83ed797f6e0f385e72a56aa7bafdf23d490 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Bouya?= Date: Sun, 17 Sep 2017 19:05:41 +0200 Subject: Enhance install script, and add ip6 address --- .../files/services/en-dhcp.network | 8 --- modules/base_installation/lib/facter/ldapvar.rb | 83 +++++++++++----------- modules/base_installation/manifests/services.pp | 13 ++-- .../templates/services/en-dhcp.network.erb | 13 ++++ 4 files changed, 63 insertions(+), 54 deletions(-) delete mode 100644 modules/base_installation/files/services/en-dhcp.network create mode 100644 modules/base_installation/templates/services/en-dhcp.network.erb (limited to 'modules/base_installation') 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 @@ -[Match] -Name=en* - -[Network] -DHCP=yes - -[DHCP] -UseMTU=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 @@ -require 'ldap' -require 'puppet/util/ldap/connection' - -Facter.add("ldapvar") do - setcode do - if Puppet[:node_terminus].to_sym != :ldap - data = [] - else - begin - conn = Puppet::Util::Ldap::Connection.instance - conn.start - connection = conn.connection - rescue ::LDAP::ResultError => e - raise Puppet::ParseError, ("ldapquery(): LDAP ResultError - #{e.message}") - end - - host = Facter.value('ec2_metadata')["hostname"] - base = Puppet[:ldapbase] - scope = ::LDAP::LDAP_SCOPE_SUBTREE - filter = "(objectclass=*)" - - data = { - :self => {}, - :other => [], - } - - connection.search(base, scope, filter) do |entry| - data_ = entry.to_hash - data_['vars'] = (data_[Puppet[:ldapstackedattrs]] || []) - .map { |var| var.split("=", 2) } - .group_by { |(key, value)| key } - .map { |key, value| [key, value.map(&:last)] } - .to_h - - data[:other] << data_ +begin + require 'ldap' + require 'puppet/util/ldap/connection' + + Facter.add("ldapvar") do + setcode do + if Puppet[:node_terminus].to_sym != :ldap + data = [] + else + begin + conn = Puppet::Util::Ldap::Connection.instance + conn.start + connection = conn.connection + rescue ::LDAP::ResultError => e + raise Puppet::ParseError, ("ldapquery(): LDAP ResultError - #{e.message}") + end - if data_["cn"].any? { |cn| cn == host } - data[:self] = data_ + host = Facter.value('ec2_metadata')["hostname"] + base = Puppet[:ldapbase] + scope = ::LDAP::LDAP_SCOPE_SUBTREE + filter = "(objectclass=*)" + + data = { + :self => {}, + :other => [], + } + + connection.search(base, scope, filter) do |entry| + data_ = entry.to_hash + data_['vars'] = (data_[Puppet[:ldapstackedattrs]] || []) + .map { |var| var.split("=", 2) } + .group_by { |(key, value)| key } + .map { |key, value| [key, value.map(&:last)] } + .to_h + + data[:other] << data_ + + if data_["cn"].any? { |cn| cn == host } + data[:self] = data_ + end end - end - data + data + end end end +rescue LoadError + # No facts end - 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 { group => "root" } + $ip6 = lookup("ips.v6") |$key| { {} } file { '/etc/systemd/network/en-dhcp.network': - ensure => "present", - path => "/etc/systemd/network/en-dhcp.network", - source => 'puppet:///modules/base_installation/services/en-dhcp.network', - mode => "0644", - owner => "root", - group => "root" + ensure => "present", + path => "/etc/systemd/network/en-dhcp.network", + content => template('base_installation/services/en-dhcp.network.erb'), + mode => "0644", + owner => "root", + group => "root" } } 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 @@ +[Match] +Name=en* + +[Network] +DHCP=ipv4 + +<%- unless @ip6.empty? -%> +Address=<%= @ip6["ipAddress"] %>/<%= @ip6["mask"] %> +Gateway=<%= @ip6["gateway"] %> +<%- end -%> + +[DHCP] +UseMTU=true -- cgit v1.2.3