Creare risorse iterando una array in Puppet
Per generare delle risorse simili, senza ridichiararle ogni volta, è possibile utilizzare un array.
- Questo codice
$users = ['kermit', 'beaker', 'statler',]
user { $users:
ensure => present,
comment => 'who gave these muppets user accounts?',
}
- Corrisponde a questo:
user { kermit:
ensure => present,
comment => 'who gave these muppets user accounts?',
}
user { beaker:
ensure => present,
comment => 'who gave these muppets user accounts?',
}
user { statler:
ensure => present,
comment => 'who gave these muppets user accounts?',
}
- TODO: verificare che funzioni anche l'utlizzo con array di array (hashes)
- TODO: verificare che la funzione create_resurces sia compatibile con almeno 2.6.7 di wheezy
$defaults = {
ensure => present,
comment => 'a muppet',
}
$data = {
'kermit' => {
comment => 'the frog',
},
'beaker' => {
comment => 'keep him away from your glassware',
},
'fozzie' => {
home => '/home/fozzie',
},
'tom' => {
comment => 'the swedish chef',
}
}
create_resources('user', $data, $defaults)