Report Templates, Safemode, and Returning Puppet Environment

When using report templates - how does one return the environment?
Without safemode - host.environment.to_s works great
With safemode - that is “jailed”. There is no evidently named “environment” method on the host class (from the Report Help Tab)

With normal ERB snippets - i have no problem doing:

However within a very simplified report:
<%- load_hosts(search: input(‘hosts’)).each_record do |host| -%>
<%- report_row({
‘Host FQDN’:,
}) -%>

I am given the error: There was an error rendering the TEST Patching template: undefined local variable or method host_puppet_environment' for #<Foreman::Renderer::Scope::Report:0x00007fbafaeffad0> Did you mean? host_puppet_classes Similarly trying with something like returns: There was an error rendering the TEST Patching template: undefined method host_puppet_environment’ for #Host::Managed:0x000055a362367760 Did you mean? hosts_api_ansible_inventories_path

Expected outcome:
How do i return a host’s “Environment” when utilizing Safe Mode in a Report Template?

Foreman and Proxy versions:
Foreman 3.0.1

Foreman and Proxy plugin versions:
Foreman 3.0.1 Equivalents

Distribution and version:
RedHat 8.4

Hi @Lang_Jason,

Sorry for the delay. I’ve checked and I didn’t found any proper macro that can be used in a report template to get the host’s Puppet environment. I’ve opened an issue [1] to track this.

[1] - Feature #34025: Add macros to retrieve puppet env for a host - Puppet - Foreman

1 Like

hi @ofedoren,

have you been able to fix this problem?

I just migrated from foreman 2.5 to 3.0 and I also encountered this problem, I have a “snippet” that uses the variable @host.environment.

Backtrace for 'Error rendering the test template' error (Safemode::NoMethodError): undefined method '#environment' for Host::Managed::Jail (Host::Managed)


ok i use <%= host_puppet_environment %> and it works