Look for create report template to list hosts with an installed package

I would like create a custom report template to list hosts with defined installed packages given in input field (“packages filters”, like there is “hosts filters” input in several reports).
For information, I use this sort of command with hammer while waiting for a better solution:

hammer host list --search 'installed_package ~pkg-name'

Having ability to generate reports with the version of the package in a collumn would be great.
Thank you for your help.

Hi @spaillet,

I’ve created a basic template to gather host names based on installed packages:

<%- load_hosts(includes: :installed_packages).each_record do |host|
      pkgs = input('packages').split(',')
      host_pkgs = host.installed_packages.map { |p| pkgs.include?(p.name) ? p : nil }.compact
      unless host_pkgs.empty?
        contains = {}
        host_pkgs.each { |p| contains.update({ p.name => p.nvrea }) }
          'Host': host.name
<%= report_render %>

For this to work, you need to have a template input called packages (you can add it whilst creating a template). As its value you need to specify a comma-separated list of packages, e.g:

Example output in CSV:


You can always modify the template for you needs :slight_smile:


Hello @ofedoren
Thank you so much, it’s exactly what I need :ok_hand:

Clearly I wouldn’t have found it on my own. With your snippet as an example, I will be able to study the syntax of the reports templates.

Proposal to the foreman team: a git repository with various templates like the old community tempates repo would be great.

1 Like

Good to read that it helped :slight_smile: Actually this repo is part of Foreman now, so you can find them here: https://github.com/theforeman/foreman/tree/develop/app/views/unattended. Other templates you can find in foreman_remote_execution or katello plugins.

Also, on Templates DSL page in Foreman you can find Help tab with few hint on to how to write reports.

I was thinking more of a repository that would contain templates that are not included with The foreman by default, where users could share reports templates they use.

Well, if users will contribute there it may reduce posts here since the answer is probably can be found in that repo… For it me makes sense, but @tbrisker ^^

1 Like