Atm I am writing a small module adding new interfaces to /etc/network/interfaces.
Therefor a hash is placed in the hiera file which is parsed and concatenated to the file.
Each fragment gets a number which is incremented. How can i order the fragments numeric wise?
network_custom::interfaces:
em4:
ipaddress: '175.21.0.15'
network: '175.21.0.0'
broadcast: '175.21.0.255'
dns-search: 'xxx.xxx.de'
em5:
ipaddress: '175.21.0.131'
network: '175.21.0.0'
broadcast: '175.21.0.255'
dns-search: 'xxx-xxx.yyy.de'
class network_custom::debian{
concat { '/etc/network/interfaces':
ensure => present,
}
$interfaceconfigs = hiera_hash(network_custom::interfaces)
$interfaceslist = keys($interfaceconfigs)
$count = inline_template( '<%= $c = $c || 0; $c = 0 %>' )
each($interfaceslist) |$interfacename|{
$count = inline_template( '<%= $c = $c || 0; $c = $c + 1 %>' )
concat::fragment { $interfacename:
target => '/etc/network/interfaces',
content => "auto ${interfacename}\niface ${interfacename} inet static\n",
order => $count
}
$interfaceconf = $interfaceconfigs[$interfacename]
each($interfaceconf) |String $key, String $value|{
$count = inline_template( '<%= $c = $c || 0; $c = $c + 1 %>' )
concat::fragment { "${interfacename}${key}":
target => '/tmp/etc/network/interfaces',
content => " ${key} ${value}\n",
order => $count
}
}
}
↧