Ask Your Question

How to filter hash in puppet manifest?

asked 2016-01-24 10:24:11 -0600

captain gravatar image

Hi all, could you please help me. I'm getting dict from hiera in puppet manifest and then trying to filter it and pass in a python script as args.But have an issues.

My hiera:

   'serv_name': 'testname'   
   'serv_hostname': 'testhost'   
   'test_url': '' 
   'serv_name': 'testname2'
   'serv_hostname': 'testhost2'
   'test_url': 'test@url.com2'

My puppet manifest(i'm getting hash from values in hiera):

$server_conf = hiera_hash('myclass::server_conf', {})

As result of this i had $server_conf which contain:

{"first_serv"=>{"serv_name"=>"testname", "serv_hostname"=>"testhost", "test_url"=>""}, "second_serv"=>{"serv_name"=>"serv2", "serv_name"=>"testname2", "serv_hostname"=>"testhost2", "test_url"=>"test@url.com2"}}

Then i want to select from this list only values:

'testname' 'testhost' '' 'testname2' 'testhost2' 'test@url.com2'

I'm trying to do it using map function:

$transforrmed_data = map(server_conf) |$key,$value| { $value }

And getting error:

Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Could not match |$key,$value| at /manifests/server.pp:26 on node test.node

How can i solve this problem? Also I need to transfer to one more variable 'testname2' 'testhost2' 'test@url.com2' and pass it to exec command resource. Or somehow run exec command twice with values from first_serv and second_serv. Thanks for any help!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2016-02-03 16:16:04 -0600

jon6000 gravatar image

Hi there,

I noticed you're missing a $ in front of server_conf in your map function.

If you install the puppetlabs/stdlib module, the 'values' and 'flatten' functions can help you out here. The following code will return an array containing the nested values you want:

flatten( map($server_conf) |$key,$value| { values($value) })


[testname, testhost,, testname2, testhost2, test@url.com2]

If you remove the 'flatten' funcion you'll get an array of two arrays containing the firstserv and secondserv values respectively:

map($server_conf) |$key,$value| { values($value) }


[[testname, testhost,], [testname2, testhost2, test@url.com2]]

These could then be passed to your exec resource.

Hope this helps,


edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2016-01-24 10:17:07 -0600

Seen: 1,452 times

Last updated: Feb 03 '16