Report template with summary of os


I am struggling for some time to create a report that would create a summary of operating systems connected to foreman using facts. For example

Ubuntu   18.04.05   13
Ubuntu   20.04.01    8

Is it possible using report templates and I am just doing something wrong here or it is not and I should look for different way of accomplishing this?


Hi @rapiertg,

Sorry if I misunderstood what you’re trying to achieve, but if you need to see OS with the number of associated hosts, but based on reported facts, you can try this snippet out:

<%- os_counter = {} -%>
<%- load_hosts(includes: :operatingsystem).each_record do |host| -%>
  <%- if host.facts["os::name"] == && host.facts["os::release::full"] == host.operatingsystem.release -%>
    <%- os_counter["#{} #{host.operatingsystem.release}"] ||= 0 -%>
    <%- os_counter["#{} #{host.operatingsystem.release}"] += 1 -%>
  <%- end -%>
<%- end -%>
<%- os_counter.each { |os, count| report_row({ name: os, count: count }) } -%>
<%= report_render %>

This is not so optimized due to lack of additional macros, but what it does is: load hosts, checks if its OS name and version are in the its reported facts, adds OS name and version to the os_counter, updates count and then prints something like:

CentOS 7.6.1810,2

You can always adjust the snippet for your needs :slight_smile:

1 Like

Thank you @ofedoren! I exactly needed what you submitted in sense of the logic! I modified it a bit because CentOS is using some other facts then Ubuntu, but now I finally get the expected data.

1 Like

@rapiertg can you then share your modify version? Thanks