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

Commit 678f10d

Browse files
author
Benedikt Braunger
committed
added support for rhel route6 files to mroute.pp
1 parent 1d21a1f commit 678f10d

File tree

3 files changed

+64
-11
lines changed

3 files changed

+64
-11
lines changed

manifests/mroute.pp

Lines changed: 51 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# == Definition: network::mroute
22
#
33
# Manages multiples routes on a single file
4-
# Configures /etc/sysconfig/networking-scripts/route-$name on Rhel
4+
# Adds up to 2 files on RHEL:
5+
# route-$name and route6-$name under /etc/sysconfig/networking-scripts
56
# Adds 2 files on Debian:
67
# One under /etc/network/if-up.d and
78
# One in /etc/network/if-down.d
@@ -31,6 +32,9 @@
3132
# Template to use to manage route up setup. Default is defined according to
3233
# $::osfamily
3334
#
35+
# [*route6_template*]
36+
# Template to use to manage route6 up script. Used only on RedHat family.
37+
#
3438
# [*route_down_template*]
3539
# Template to use to manage route down script. Used only on Debian family.
3640
#
@@ -45,7 +49,7 @@
4549
# === Actions:
4650
#
4751
# On Rhel
48-
# Deploys the file /etc/sysconfig/network-scripts/route-$name.
52+
# Deploys the files route-$name and route6-$name in /etc/sysconfig/network-scripts
4953
#
5054
# On Debian
5155
# Deploy 2 files 1 under /etc/network/if-up.d and 1 in /etc/network/if-down.d
@@ -59,10 +63,25 @@
5963
$config_file_notify = 'class_default',
6064
$ensure = 'present',
6165
$route_up_template = undef,
66+
$route6_template = undef,
6267
$route_down_template = undef,
6368
) {
6469
# Validate our arrays
6570
validate_hash($routes)
71+
$ipv6_routes = $routes.reduce({}) |$memo, $value| {
72+
if $value[0] =~ Stdlib::IP::Address::V6 {
73+
$memo + { $value[0] => $value[1], }
74+
} else {
75+
$memo
76+
}
77+
}
78+
$ipv4_routes = $routes.reduce({}) |$memo, $value| {
79+
if $value[0] =~ Stdlib::IP::Address::V4 {
80+
$memo + { $value[0] => $value[1], }
81+
} else {
82+
$memo
83+
}
84+
}
6685

6786
include ::network
6887

@@ -79,6 +98,15 @@
7998
},
8099
default => $route_up_template,
81100
}
101+
102+
$real_route6_template = $route6_template ? {
103+
undef => $::osfamily ? {
104+
'RedHat' => 'network/mroute6-RedHat.erb',
105+
default => undef,
106+
},
107+
default => $route6_template,
108+
}
109+
82110
$real_route_down_template = $route_down_template ? {
83111
undef => $::osfamily ? {
84112
'Debian' => 'network/mroute_down-Debian.erb',
@@ -96,14 +124,27 @@
96124

97125
case $::osfamily {
98126
'RedHat': {
99-
file { "route-${name}":
100-
ensure => $ensure,
101-
mode => '0644',
102-
owner => 'root',
103-
group => 'root',
104-
path => "/etc/sysconfig/network-scripts/route-${name}",
105-
content => template($real_route_up_template),
106-
notify => $real_config_file_notify,
127+
unless $ipv4_routes.empty {
128+
file { "route-${name}":
129+
ensure => $ensure,
130+
mode => '0644',
131+
owner => 'root',
132+
group => 'root',
133+
path => "/etc/sysconfig/network-scripts/route-${name}",
134+
content => template($real_route_up_template),
135+
notify => $real_config_file_notify,
136+
}
137+
}
138+
unless $ipv6_routes.empty {
139+
file { "route6-${name}":
140+
ensure => $ensure,
141+
mode => '0644',
142+
owner => 'root',
143+
group => 'root',
144+
path => "/etc/sysconfig/network-scripts/route6-${name}",
145+
content => template($real_route6_template),
146+
notify => $real_config_file_notify,
147+
}
107148
}
108149
}
109150
'Debian': {

templates/mroute-RedHat.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
###
22
### File managed by Puppet
33
###
4-
<% @routes.each do |net,gw| -%>
4+
<% @ipv4_routes.each do |net,gw| -%>
55
<%= net -%>
66
<%
77
if gw.kind_of?(Array)

templates/mroute6-RedHat.erb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
###
2+
### File managed by Puppet
3+
###
4+
<% @ipv6_routes.each do |net,gw| -%>
5+
<%= net -%>
6+
<%
7+
if gw.kind_of?(Array)
8+
gw.each do | g | %> nexthop via <%= g %><% end %>
9+
<%- elsif /^\d/.match(gw) %> via <%= gw %>
10+
<%- else %> dev <%= gw %>
11+
<%- end -%>
12+
<% end -%>

0 commit comments

Comments
 (0)