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

Hello,
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 }) }
        report_row({
          'Host': host.name
        }.merge(contains))
      end
    end
-%>
<%= 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:

Host,audit
ktest.nuka.com,audit-2.8.5-4.el7.x86_64

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

5 Likes

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.

2 Likes

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

Hi all, sorry for resurrecting an old thread, but I’m trying to get the packages on my hosts and everything is pointing to “installed_packages” doesn’t exist. For example, if I try this via hammer:

hammer host list --search ‘installed_package ~pkg-name’

I get the message:

Field ‘installed_package’ not recognized for searching!

Is there some package I’m missing?

Looks like installed packages is part of Katello, which is why I’m missing it: I’m on a stand-alone foreman instance. I guess I need to figure out how to migrate.

Unfortunately no in-place migration, so you need to setup a new environment ans switch systems over. I know it is more complex in reality, but as a short hint for you to look for.

1 Like

Hello All,

I have done the setup of redhat satellite version 6.13 wherein i want to generate an valid list of report based on all hosts on below scenario:-
1] List of all host which are patch and non-patch. [including data and its pie chart]
2] Show list of patching done and not done based on all hosts patching status from point 1

In a pdf manager not by csv or excel sheet.