On 02/04/2011 03:26 PM, Chip wrote:
> I have a hash with network information structured as such:
> 
> $networkinfo = {
>       'machine1.domain.local' => { eth0 => { ip => '192.168.1.50',
> mask => '255.255.255.0', gw => '192.168.1.254'  },
>             eth1 => { ip => '192.168.2.68', mask =>
> '255.255.255.0' } },
>       'machine2.domain.local' => { eth0 => { ip => '192.168.1.51',
> mask => '255.255.255.0', gw => '192.168.1.254'  },
>             eth1 => { ip => '192.168.2.74', mask =>
> '255.255.255.0' } }
> }
> 
> In a function I need to access data in this hash without hard coding
> everything.
> 
> $ipaddress = $networkinfo["$fqdn"]"[$iface"]['ip']
> 
> this fails with syntax errors unless specify everything such as
> 
> $ipaddress = $networkinfo['machine1.domain.local']['eth2']['ip']
> 
> What is the proper syntax to access data within the hash?

Interesting - in a short test, I don't even get your final example
working. (This is 2.6.2.)

However, this seems to be a problem with the syntax of nested hashes, as
this Works For Me:

$all = $networkinfo[$nodename][$iface]
$address = $all[ip]
notify { "check": message => "retrieved address $address" }

You may wish to raise a possible bug.

HTH,
Felix

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en.

Reply via email to