Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Is it possible to define an array in this format in my nodes.pp?

$servers = [
    {
        name => 'felix',
        ip   => '192.168.43.5',
        env  => 'prod',
    },
    {
        name => 'washington',
        ip   => '192.168.43.11',
        env  => 'uat',
    },
]

Thanks Dan

share|improve this question

1 Answer 1

I don't find any reasons why that wouldn't work. Taken from the puppet docs:

$foo = [ 'one', {'second' => 'two', 'third' => 'three'} ]
notice( $foo[1]['third'] )

Not sure if the data has to be nested like that, due to some requirements, but wouldn't be more logical to organise the data like that ?

$servers = {
   felix      => { ip => '192.168.43.5',
                   env => 'prod', 
                 },
   washington => { ip => '192.168.43.11',
                   env => 'uat',
                 },
}
share|improve this answer
    
When I try it I keep getting puppet errors, so if I do this: def::server::list { servers: $servers = [ { name => 'felix', ip => '192.168.43.5', env => 'prod', }, { name => 'washington', ip => '192.168.43.11', env => 'uat', }, ]} Why wouldn't that work? I keep getting the error: Error 400 on SERVER: Could not parse for environment production: Syntax error at 'servers'; expected '}' Thanks Dan –  Dan Feb 14 '13 at 13:37
    
The reason for that error is usually missing commas and/or colons. Double check the definition of your variable. Also I really don't understand why you were trying to do with that example. –  golja Feb 14 '13 at 13:58
    
Also send me the definition of the def::server::list class. It's possible that your defined type expect a different type for argument. –  golja Feb 14 '13 at 22:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.