Report Template Fact: <%= host.facts['mountpoints']['/']['capacity'] %>

I’m trying to build a Report Template that outputs the root mount point disk used

Expected outcome:
A “percentage used” of the root mount point is output

Foreman and Proxy versions:

Foreman and Proxy plugin versions:

Distribution and version:

Other relevant data:
The <%= host.facts[‘mountpoints’][’/’][‘capacity’] %> variable in my Report Template gives the following error:

undefined method `’ for nil:NilClass

1 Like


it looks like some [] method in the chain returned nil. One or more of your hosts don’t have either mountpoints (facter 2.x perhaps) or don’t have “capacity”. Whatever.

You can use nice Ruby trick: host.facts.dig("mountpoints").dig("/").dig("capacity") however the dig method might not be in the list of safemode methods

Yeah I have just checked safemode, you need to turn it off in Administer - Settings or hotfix your instance:

Also please share the report template with the rest of the community:

This isn’t the correct way of using dig since you may end up calling nil.dig. If dig was allowed, the correct way is host.facts.dig('mountpoints', '/', 'capacity').

Yeah sorry, that was indeed the intention. All the rest applies.

Thank you for the help!

I confirmed safemode was off in Settings(Safemode rendering = No) and the hotfix applied, but host.facts.dig('mountpoints', '/', 'capacity') in my template didn’t work. My output report just shows blanks.

I can confirm the values exist. When I hit this URL: https://<server>/fact_values?search=name+%3D+mountpoints%3A%3A%2F%3A%3Acapacity, it shows the percentage values.

Can you print the wholehost.facts or host.facts.inspect to see the value?

Method facts return facts in Ruby hash, so syntax “mountpoints::/::capacity” whould not work there I assume.

Yep, it’s in there:

... , "mountpoints::/::capacity"=>"29.98%", ...

Got it! Simply put the following in my Report Template:

<%= host.facts[“mountpoints::/::capacity”] %>

Thanks again for the help!

1 Like

Oh I thought we return structured hash. Interesting, noted.