PuppetDB 5.2: How to find list of certnames from puppetdb where serverrole is "umg" using API

136 views
Skip to first unread message

Biraj Sahu

unread,
Jul 16, 2019, 1:16:03 PM7/16/19
to Puppet Users

PuppetDB version- 5.2

I want to retrieve list of servers with a specific role- tata_umg



The json is in below format:

[

 {

     "certname":"<hostname>",

     "environment":"xxxx",

     "name":"xxxx_clientname",

     "value":{

        "clientabc":{

           "xxxx_productname":{

              "tata":{

                 "xxxx_instanceid":"0",

                 "xxxx_serverrole":[

                    "tata_umg"

                 ]

              }

           }

        }

     }

  }]

Can use below 2 get requests to reterive:

curl -X GET 'http://puppetdb.aws.internal:8080/pdb/query/v4/facts/xxxx_clientname'

curl -X GET 'http://puppetdb.aws.internal:8080/pdb/query/v4/facts' --data-urlencode 'query=["=", "name", "xxxx_clientname"]'



But this gives me a json with all server's - 'xxxx_clientname' and not specific to a certain role.



Can anyone please help me update the query to make it work as per my need.

Austin Blatt

unread,
Jul 16, 2019, 6:25:45 PM7/16/19
to puppet...@googlegroups.com
Apologies in advance if I didn't interpret your query properly, but I believe you are looking to return the certnames of servers that have a specific fact with a specific value, the best endpoint for that would probably be inventory (or maybe fact-contents). A curl command for the inventory endpoint could look like this.

curl -X POST http://<your-server>:8080/pdb/query/v4 \
  -H 'Content-Type:application/json' \
  -d '{"query": "inventory[certname] { facts.path.to.fact = \"your-value\" }" }'

The fact-content query would look similar, but you'd need to match path and value there and it doesn't support dot notation like the inventory endpoint.

--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/8d2e4bc6-762e-4349-ac28-e20d587d36df%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Austin Blatt
Associate Software Engineer

Biraj Sahu

unread,
Jul 17, 2019, 6:11:12 AM7/17/19
to austin...@puppet.com, puppet...@googlegroups.com
Hello Austin,
Thanks for your reply.

The issue is I am trying to return certnames based on server_role which I dont think is a fact, correct me if I am wrong. And since puppet 5.2, we have nested key, values and not sure how do I reach that leaf. Please check the json snippet, if you haven't checked yet.

Thanks
Biraj


For more options, visit https://groups.google.com/d/optout.


--
BIRAJ
Pune
Ph no-08861077222
Reply all
Reply to author
Forward
0 new messages