Skip to content
This repository has been archived by the owner on Nov 11, 2021. It is now read-only.

added support for rhel route6 files to mroute.pp #262

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 51 additions & 10 deletions manifests/mroute.pp
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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.
#
Expand All @@ -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
Expand All @@ -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

Expand All @@ -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',
Expand All @@ -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': {
Expand Down
2 changes: 1 addition & 1 deletion templates/mroute-RedHat.erb
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
12 changes: 12 additions & 0 deletions templates/mroute6-RedHat.erb
Original file line number Diff line number Diff line change
@@ -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 -%>