Formatting HTML report output?

I have a job template with type ansible playbook. This playbook gathers some data from hosts and formats it a bit and saves that as a fact. I also have a reporting template which then references that fact and prints it out in a row alongside the hostname. The problem I’m having is my preferred report output is HTML, however the fact portion generates in the HTML report as one long string of text. I’ve tried to format it both in the job playbook and the reporting end many times and just can’t seem to figure it out. I just need new lines!! I’ve tried inserting \n or html breaks but it seems to escape html. Does anyone have any suggestions? Find below my final set fact task, as well as my reporting ERB.

Set fact task:

- name: Set individual output fact for each host
set_fact:
validation_check: |
Rocky Release: {{ rocky_release.stdout }}
Uptime: {{ system_uptime.stdout }}
Kernel: {{ kernel_version.stdout }}
Host was patched within the last 5 hours: {{ patch_check.stdout }}
Kernel Check: {{ kernel_check.stdout }}
Reboot Check: {{ reboot_check.stdout }}

ERB snippet:

<%- report_headers ‘Hostname’, ‘Validation’ -%>
<%- load_hosts(search: “host_collection_id = #{input(‘host_collection_selector’)}”).each_record do |host| -%>
<%- report_row({
‘Hostname’: host.name,
‘Validation’: host.facts[‘validation_check’] || ‘N/A’,
}) -%>
<%- end -%>
<%= report_render -%>

Can I see an example of the expected and actual output?

Absolutely. As you can see here this is the HTML report of a single host displaying its facts. It displays it in one long line when the intended result would be line breaks as displayed in the original ansible task that set the fact.

Realistically I could just gather each of my fact items separately and then display them one at a time. It’s the fact I’m gathering several OS items and then formatting them into a single fact that I think is causing the issue. I’d prefer to just be able to format the HTML though.

Not sure if newlines will work here, because the HTML formatting is quite basic, but you could try something like

‘Validation’: host.facts[‘validation_check’].keys.map { |k| "#{k}: #{host.facts[‘validation_check’][k]}" }.join("\n")