Ask Your Question

How to reorganise a hash [closed]

asked 2018-09-27 18:19:13 -0600

merdmann gravatar image

updated 2018-09-28 07:49:49 -0600

DarylW gravatar image

I have a puppetdb query: "resources[certname,parameters]{type = 'my_special_type'}". The result looks like this:

    "certname": "server1",
    "parameters": {
      "port": 1234,
      "job": "job1"

Imagine a few dozen servers with five different jobs. Is there a way to transform that into an object that looks like:

    "job": "job1",
    "entries": ["server1:1234"]

Either by changing the query, or by using various Puppet functions to create a new hash? Is this possible directly in Puppet, or should I give up and write a function in Ruby which can be called from Puppet (note: I'm not even sure that it's possible to pass a structure back to Puppet)? If you need to know why I'm doing this: I'm trying to get nodes to self identify for various Prometheus scans. I've got that part working, so I can collect the necessary information form PuppetDB. Now I need to sort through it and create a config file.

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by merdmann
close date 2018-10-02 11:36:05.951088

1 Answer

Sort by ยป oldest newest most voted

answered 2018-10-01 11:52:07 -0600

MichaelSmith gravatar image

This should be possible with map and reduce. There are a few primitives that would make this easier (group_by or partition) that aren't part of the core Puppet distribution, but we can work around them.

I've created an example at

edit flag offensive delete link more


This is exactly what I was looking for. Thank you so much!

merdmann gravatar imagemerdmann ( 2018-10-02 11:34:40 -0600 )edit

Question Tools

1 follower


Asked: 2018-09-27 18:19:13 -0600

Seen: 92 times

Last updated: Oct 01