|
1 | 1 | # == Definition: network::mroute
|
2 | 2 | #
|
3 | 3 | # 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 |
5 | 6 | # Adds 2 files on Debian:
|
6 | 7 | # One under /etc/network/if-up.d and
|
7 | 8 | # One in /etc/network/if-down.d
|
|
31 | 32 | # Template to use to manage route up setup. Default is defined according to
|
32 | 33 | # $::osfamily
|
33 | 34 | #
|
| 35 | +# [*route6_template*] |
| 36 | +# Template to use to manage route6 up script. Used only on RedHat family. |
| 37 | +# |
34 | 38 | # [*route_down_template*]
|
35 | 39 | # Template to use to manage route down script. Used only on Debian family.
|
36 | 40 | #
|
|
45 | 49 | # === Actions:
|
46 | 50 | #
|
47 | 51 | # 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 |
49 | 53 | #
|
50 | 54 | # On Debian
|
51 | 55 | # Deploy 2 files 1 under /etc/network/if-up.d and 1 in /etc/network/if-down.d
|
|
59 | 63 | $config_file_notify = 'class_default',
|
60 | 64 | $ensure = 'present',
|
61 | 65 | $route_up_template = undef,
|
| 66 | + $route6_template = undef, |
62 | 67 | $route_down_template = undef,
|
63 | 68 | ) {
|
64 | 69 | # Validate our arrays
|
65 | 70 | 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 | + } |
66 | 85 |
|
67 | 86 | include ::network
|
68 | 87 |
|
|
79 | 98 | },
|
80 | 99 | default => $route_up_template,
|
81 | 100 | }
|
| 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 | + |
82 | 110 | $real_route_down_template = $route_down_template ? {
|
83 | 111 | undef => $::osfamily ? {
|
84 | 112 | 'Debian' => 'network/mroute_down-Debian.erb',
|
|
96 | 124 |
|
97 | 125 | case $::osfamily {
|
98 | 126 | '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 | + } |
107 | 148 | }
|
108 | 149 | }
|
109 | 150 | 'Debian': {
|
|
0 commit comments