Steve Neuharth
2014-Mar-10 20:42 UTC
[Puppet Users] how do I check to see whether a hash value is defined if a parent of the hash value might not even exist?
I've got a big hash of info that looks like this: $web_conf = { my_client => { dev => { ws => { server_name => 'ws.foo.bar', server_aliases => ['ws.dev.bar.foo.com', 'ws.dev.another.foo.com'], }, csr => { server_aliases => ['csr.dev.bar.foo.com', 'csr.dev.another.foo.com'], }, mw => { server_aliases => ['mw.dev.bar.foo.com', 'mw.dev.another.foo.com'], }, }, } I'm trying to do something like this in my manifest: # set up our servername if $web_conf[$::client][$::env][$name]['server_name'] { $server_name = $web_conf[$::client][$::env][$name]['server_name'] } else { $server_name = "${name}.${client_code}.${::env}.${domain}" } The thought was that I'd have servers that follow a certain naming convention and ones that don't. The ones that have 'special' names go in the web_conf hash. If the manifest 'sees' a server name in the hash, it should use that. If not, then it just does the 'else' bit. The trouble is that it totally fails if even the top or intermediate levels of the hash don't exist. I've tried using "if $web_conf[$::client][$::env][$name]['server_name'] != undef", tried "if undef($web_conf[$::client][$::env][$name]['server_name'])" etc. what's the correct way to do this? --steve -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscribe@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/8b3ba3ea-5c1c-488f-94a5-4c582a021c84%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.