Report Template - facts

Problem:
How do you retrieve a particular host’s fact-value called os_patching?
Expected outcome:
Hostname and fact-value displayed in a report
Foreman and Proxy versions:
1.22
Foreman and Proxy plugin versions:

Other relevant data:
[e.g. logs from Foreman and/or the Proxy, modified templates, commands issued, etc]
(for logs, surround with three back-ticks to get proper formatting, e.g.)

logs

Hello,

this should work

<%- load_hosts.each_record do |host| -%>
<%-   report_row(
        'Name': host.name,
        'Fact': host.facts_hash['os_patching']
      ) -%>
<%- end -%>
<%= report_render -%>

please note that this is probably not efficient as it loads all facts for every hosts as a separate SQL query. Perhaps facts could be preloaded, but that could consume also more memory.

1 Like

Thanks that solved it :slight_smile:

Hi all,
Do you know how to print nested facts?
For example:
dmi.product.name
Trying to use it within the report doesn’t throw any errors but is not populating it:
host.facts_hash["dmi.product.name"]

In the client “facter dmi.product.name” works fine, but still coming out empty in the report.

Also, do you know any documentation about writing these templates?
I can’t find anything at all.

Thanks!

Try host.facts_hash["dmi"]["product"]["name"] it may work. Find the DSL docs under Administer -> About, see the “Templates DSL” link. Hope this helps.

1 Like