Getting foreman search results into your Puppet manifest


Lets say you want to know all of the hosts your monitoring host need to monitor, or maybe, the hosts to which your database needs to allow access to, traditionally, the solution to this problem was using Puppet storeconfigs.

In this blog post, I mentioned how you could utilize foreman search language to get customized results.

While storeconfigs is a great solution, and if it works for you, by all means, please do keep using it, but in this post I would like to show you how to use Foreman to query for similar data + foreman data as well.

Lets say, we want to allow VPN access only to client hosts which ran puppet in the last week.

You could easily change the search conditions, for example, to get a list of hosts without any puppet failures, simply change the query to status.failed = 0.

we could easily search for conditions based on facts, puppet classes, owner, reports and combination of them.

the output from the puppet function, may include complex data, such as Arrays and Hashes as well, and it depends on the query object used, for example, host lists would mostly be an Array, however, host facts would be a hash, for example:

which you could utilize either in templates or versions of puppet that supports hashes.

Quick start

  1. Install and setup foreman (Foreman puppet modules might be a quick starting point).
  2. If you are not using the official foreman installer, download and put the following file in your modules lib directory, and ensure you are using pluginsync.
  3. adjust the file to point to your foreman server.
  4. use it in your manifest.

Comments from the community:


Foreman 1.20.0 has been released! Follow the quick start to install it.

Foreman 1.19.1 has been released! Follow the quick start to install it.

Foreman 1.18.3 has been released! Follow the quick start to install it.