Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Edwin Wiles committed Oct 22, 2017
1 parent c44cee2 commit 7fc0303
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 11 deletions.
37 changes: 26 additions & 11 deletions manifests/route.pp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@
# gateway => [ '192.168.1.1', '10.0.0.1', ],
# }
#
# network::route { 'ens192':
# ipaddress => [
# '192.168.2.0/24 via 192.168.1.1',
# '10.0.0.0/8 via 10.0.0.1'
# ]
# }
#
# === Authors:
#
# Mike Arnold <[email protected]>
Expand All @@ -41,29 +48,37 @@
# Copyright (C) 2011 Mike Arnold, unless otherwise noted.
#
define network::route (
$ipaddress,
$netmask,
$gateway,
$restart = true,
Array[String] $ipaddress,
Optional[Array[String]] $netmask = undef,
Optional[Array[String]] $gateway = undef,
Boolean $restart = true,
) {
# Validate our arrays
validate_array($ipaddress)
validate_array($netmask)
validate_array($gateway)
# Validate our booleans
validate_bool($restart)

include '::network'

$interface = $name

if $ipaddress != undef and $netmask != undef and $gateway != undef {
if length($ipaddress) == length($netmask) and length($netmask) == length($gateway) {
$template = 'network/route-eth.erb';
else {
fail { 'All arrays must be the same length': }
}
}
elsif $netmask == undef and $gateway == undef {
$template = 'network/route-eth-ip.erb';
}
else {
fail { 'Either use just ipaddress, or use all three array parameters': }
}

file { "route-${interface}":
ensure => 'present',
mode => '0644',
owner => 'root',
group => 'root',
path => "/etc/sysconfig/network-scripts/route-${interface}",
content => template('network/route-eth.erb'),
content => template($template),
before => File["ifcfg-${interface}"],
}

Expand Down
6 changes: 6 additions & 0 deletions templates/route-eth-ip.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
###
### File managed by Puppet
###
<% @ipaddress.each do |addr| -%>
<%= addr %>
<% end -%>

0 comments on commit 7fc0303

Please sign in to comment.