From 678f10de2641a5c4e7f255c20e277fddc5a5b943 Mon Sep 17 00:00:00 2001 From: Benedikt Braunger Date: Wed, 9 Jan 2019 22:14:52 +0100 Subject: [PATCH] added support for rhel route6 files to mroute.pp --- manifests/mroute.pp | 61 ++++++++++++++++++++++++++++++------ templates/mroute-RedHat.erb | 2 +- templates/mroute6-RedHat.erb | 12 +++++++ 3 files changed, 64 insertions(+), 11 deletions(-) create mode 100644 templates/mroute6-RedHat.erb diff --git a/manifests/mroute.pp b/manifests/mroute.pp index d31742b..1d50549 100644 --- a/manifests/mroute.pp +++ b/manifests/mroute.pp @@ -1,7 +1,8 @@ # == Definition: network::mroute # # Manages multiples routes on a single file -# Configures /etc/sysconfig/networking-scripts/route-$name on Rhel +# Adds up to 2 files on RHEL: +# route-$name and route6-$name under /etc/sysconfig/networking-scripts # Adds 2 files on Debian: # One under /etc/network/if-up.d and # One in /etc/network/if-down.d @@ -31,6 +32,9 @@ # Template to use to manage route up setup. Default is defined according to # $::osfamily # +# [*route6_template*] +# Template to use to manage route6 up script. Used only on RedHat family. +# # [*route_down_template*] # Template to use to manage route down script. Used only on Debian family. # @@ -45,7 +49,7 @@ # === Actions: # # On Rhel -# Deploys the file /etc/sysconfig/network-scripts/route-$name. +# Deploys the files route-$name and route6-$name in /etc/sysconfig/network-scripts # # On Debian # Deploy 2 files 1 under /etc/network/if-up.d and 1 in /etc/network/if-down.d @@ -59,10 +63,25 @@ $config_file_notify = 'class_default', $ensure = 'present', $route_up_template = undef, + $route6_template = undef, $route_down_template = undef, ) { # Validate our arrays validate_hash($routes) + $ipv6_routes = $routes.reduce({}) |$memo, $value| { + if $value[0] =~ Stdlib::IP::Address::V6 { + $memo + { $value[0] => $value[1], } + } else { + $memo + } + } + $ipv4_routes = $routes.reduce({}) |$memo, $value| { + if $value[0] =~ Stdlib::IP::Address::V4 { + $memo + { $value[0] => $value[1], } + } else { + $memo + } + } include ::network @@ -79,6 +98,15 @@ }, default => $route_up_template, } + + $real_route6_template = $route6_template ? { + undef => $::osfamily ? { + 'RedHat' => 'network/mroute6-RedHat.erb', + default => undef, + }, + default => $route6_template, + } + $real_route_down_template = $route_down_template ? { undef => $::osfamily ? { 'Debian' => 'network/mroute_down-Debian.erb', @@ -96,14 +124,27 @@ case $::osfamily { 'RedHat': { - file { "route-${name}": - ensure => $ensure, - mode => '0644', - owner => 'root', - group => 'root', - path => "/etc/sysconfig/network-scripts/route-${name}", - content => template($real_route_up_template), - notify => $real_config_file_notify, + unless $ipv4_routes.empty { + file { "route-${name}": + ensure => $ensure, + mode => '0644', + owner => 'root', + group => 'root', + path => "/etc/sysconfig/network-scripts/route-${name}", + content => template($real_route_up_template), + notify => $real_config_file_notify, + } + } + unless $ipv6_routes.empty { + file { "route6-${name}": + ensure => $ensure, + mode => '0644', + owner => 'root', + group => 'root', + path => "/etc/sysconfig/network-scripts/route6-${name}", + content => template($real_route6_template), + notify => $real_config_file_notify, + } } } 'Debian': { diff --git a/templates/mroute-RedHat.erb b/templates/mroute-RedHat.erb index c1fd76c..289da55 100644 --- a/templates/mroute-RedHat.erb +++ b/templates/mroute-RedHat.erb @@ -1,7 +1,7 @@ ### ### File managed by Puppet ### -<% @routes.each do |net,gw| -%> +<% @ipv4_routes.each do |net,gw| -%> <%= net -%> <% if gw.kind_of?(Array) diff --git a/templates/mroute6-RedHat.erb b/templates/mroute6-RedHat.erb new file mode 100644 index 0000000..c81a376 --- /dev/null +++ b/templates/mroute6-RedHat.erb @@ -0,0 +1,12 @@ +### +### File managed by Puppet +### +<% @ipv6_routes.each do |net,gw| -%> +<%= net -%> +<% + if gw.kind_of?(Array) + gw.each do | g | %> nexthop via <%= g %><% end %> + <%- elsif /^\d/.match(gw) %> via <%= gw %> + <%- else %> dev <%= gw %> + <%- end -%> +<% end -%>