Created
January 23, 2016 17:43
-
-
Save Millnert/558ecdc35089221841cc to your computer and use it in GitHub Desktop.
Puppet defined type execution order issues
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# IPnett defined type for a so called 'derived' static interface: | |
# It clones the settings of a master interface | |
# | |
# The master interface may or may not be managed automatically. | |
# The derived interface will change according to changes done to the | |
# master interface. Manual changes only: the derived interface will | |
# follow suit. Automatic changes: the derived interface will follow. | |
# | |
# $target_interface: | |
# - the interface to clone settings *to* | |
# | |
# $target_prefix: | |
# - the target prefix to replace in, in format 'a.b.c', i.e. the primrary 3 | |
# ipv4 octets of a prefix | |
# | |
# $source_interface: | |
# - the interface to clone settings *from* | |
# | |
# $target_mtu: | |
# - a specific MTU setting, otherwise MTU is cloned | |
# | |
# $target_netmask: | |
# - a specific netmask for the target interface | |
# - default: netmask is taken from the source interface | |
# | |
# $target_lastdigit: | |
# - a specific last digit for the new interface, | |
# - by default, uses the last digit of the source interface's ipaddress | |
define ipnett::network::derived_static_if ( | |
$target_prefix, | |
$target_interface = $title, | |
$target_mtu = undef, | |
$target_lastdigit = undef, | |
$target_netmask = undef, | |
$source_interface = 'eth0', | |
$soft_fail = false, | |
) { | |
if defined($target_interface) and $target_interface == $source_interface { | |
fail('Source and target interface cannot be the same') | |
} | |
if !has_interface_with($source_interface) { | |
fail('The source interface does not exist') | |
} | |
if !has_interface_with($target_interface) { | |
fail('The target interface does not exist') | |
} | |
if !is_ip_address("${target_prefix}.0") { | |
fail("target_prefix '${target_prefix}' specified in incorrect format") | |
} | |
if !defined($target_mtu) { | |
$target_mtu = getvar("mtu${::source_interface}") | |
} | |
if !defined($target_netmask) { | |
$target_netmask = getvar("netmask${::source_interface}") | |
} | |
if defined($target_lastdigit) and is_integer($target_lastdigit) { | |
$target_ipaddress = "${target_prefix}.${target_lastdigit}" | |
} else { | |
$source_ipaddress = getvar("ipaddress_${::source_interface}") | |
$target_ipaddress = regsubst($source_ipaddress, | |
'^(\d+)\.(\d+)\.(\d+)\.(\d+)', "${target_prefix}.\\4") | |
notice("target_ipaddress: ${target_ipaddress}") | |
} | |
::network::if::static { | |
$target_interface: | |
ensure => 'up', | |
ipaddress => $target_ipaddress, | |
netmask => $target_netmask, | |
mtu => $target_mtu; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment