hiera lookup , extract one element

39 views
Skip to first unread message

Helen Paterson

unread,
Nov 25, 2014, 11:59:12 AM11/25/14
to puppet...@googlegroups.com
Hi,

I have the following hiera data in the node definition. I can lookup all the data create_resources('iis::manage_site', hiera_hash('iis::sites', [])) .

iis::sites:
 'myweb1':
    site_path: 'D:\Repositories\myweb1\wwwroot'
    port: '80'
    ip_address: '192.168.33.21'
    app_pool: 'ColdFusion'
 'myweb2':
    site_path: 'D:\Repositories\myweb2\wwwroot'
    port: '81'
    ip_address: '192.168.33.22'
    app_pool: 'ColdFusion'



But how do i just extract the ip_address ?


Regards

Helen

Felix Frank

unread,
Nov 26, 2014, 5:54:26 AM11/26/14
to puppet...@googlegroups.com
Hi,

please note that

create_resources('iis::manage_site', hiera_hash('iis::sites', []))

is not the most atomic way of looking up hiera data at all. You could do
the same thing like this:

$sites = hiera('iis::sites', {})
create_resources('iis::manage_site', $sites)

This gives you the advantage of being able to just work with the $sites
hash as well.

$addr_web1 = $sites['myweb1']['ip_address']

Further notes:
1. Don't pass [] as the default value for a hash lookup. Use {}.
2. Use hiera_hash() only if you need to merge hash data from all
hierarchy layers.

HTH,
Felix

Helen Paterson

unread,
Dec 2, 2014, 10:12:43 AM12/2/14
to puppet...@googlegroups.com
Thank you so much for this reply and thank you for the detailed example.
 
( I am using deep merge aswell )
Reply all
Reply to author
Forward
0 new messages