1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| define route ( $ensure = present, $gateway = '', $route_file = 'S27route', $route_file_path = '/etc/rc3.d' ) {
validate_re($ensure, [present, 'add', absent, 'del']) validate_string($gateway) validate_string($route_file) validate_absolute_path($route_file_path)
if ! is_ip_address($gateway) { fail("The gateway must be a ipaddress.") }
if $name =~ /\// { $target_type = 'net' } else { $target_type = 'host' }
exec { "touch_route_file_$name": command => "touch ${route_file_path}/${route_file}", unless => "test -f ${route_file_path}/${route_file}", }
if ($ensure in [present, 'add']) { file_line { "$name": ensure => present, line => "${::route} add -${target_type} ${title} gw ${gateway}", path => "${route_file_path}/${route_file}", } exec { "$name": command => "${::route} add -${target_type} ${title} gw ${gateway}", refreshonly => true, subscribe => File_line[$name], } } elsif ($ensure in [absent, 'del']) { file_line { "$name": ensure => absent, line => "${::route} add -${target_type} ${title} gw ${gateway}", path => "${route_file_path}/${route_file}", } exec { "$name": command => "${::route} del -${target_type} ${title} gw ${gateway}", refreshonly => true, subscribe => File_line[$name], } }
Exec["touch_route_file_$name"] -> File_line["$name"]
}
|