Creare risorse iterando una array in Puppet: Difference between revisions

From RVM Wiki
Jump to navigation Jump to search
Created page with "Per generare delle risorse simili, senza ridichiararle ogni volta, è possibile utilizzare un array. * Questo codice <pre> $users = ['kermit', 'beaker', 'statler',] user { ..."
 
(No difference)

Latest revision as of 16:53, 14 July 2014

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)

Riferimenti