diff --git a/manifests/route.pp b/manifests/route.pp index 27c7534..0657944 100644 --- a/manifests/route.pp +++ b/manifests/route.pp @@ -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 @@ -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}"], } diff --git a/templates/route-eth-ip.erb b/templates/route-eth-ip.erb new file mode 100644 index 0000000..71a0484 --- /dev/null +++ b/templates/route-eth-ip.erb @@ -0,0 +1,6 @@ +### +### File managed by Puppet +### +<% @ipaddress.each do |addr| -%> +<%= addr %> +<% end -%>