Output results of a command using remote execution sent to several hosts?

Is there a simple way I have overlooked, sending a command using remote execution to several hosts and get the output of that command from all host to some kind of result/report?
Ex. if I send the command ‘printf "$(hostname), ";date’ to 3 hosts I want something returned in one place like:
host1.domain, Mon Aug 15 11:49:49 UTC 2022
host2.domain, Mon Aug 15 11:49:49 UTC 2022
host3.domain, Mon Aug 15 11:49:49 UTC 2022

Solution could be from web gui or cli.

One ugly solution is to just look in the /var/log/foreman/production.log. Issued the ‘printf "$(hostname), ";date’ command on two hosts and the logs goes:

2022-08-15T14:53:06 [I|app|b071efbe]   Parameters: {"callback"=>{"task_id"=>"69bfada3-dcc1-4d9a-91f9-ed9f048218e4", "step_id"=>3}, "data"=>{"result"=>[{"output_type"=>"stdout", "output"=>"rex login: ", "timestamp"=>1660575183.1536763}, {"output_type"=>"stdout", "output"=>"\nfmtestvm3.internal, Mon Aug 15 14:53:04 UTC 2022\n", "timestamp"=>1660575185.1570966}], "runner_id"=>"7395d89e-888c-4d51-9e1e-b5a359ded420", "exit_status"=>0}, "task"=>{}}
2022-08-15T14:53:07 [I|app|fa68e284]   Parameters: {"callback"=>{"task_id"=>"eacceef3-5212-4484-8aac-b542fbb37802", "step_id"=>3}, "data"=>{"result"=>[{"output_type"=>"stdout", "output"=>"rex login: ", "timestamp"=>1660575184.1566248}, {"output_type"=>"stdout", "output"=>"\nfmtestvm2.internal, Mon Aug 15 14:53:05 UTC 2022\n", "timestamp"=>1660575186.163457}], "runner_id"=>"6ae6c071-0818-4887-9848-9e4ae205052d", "exit_status"=>0}, "task"=>{}}

So cleaning it up:

IFS=$'\n';for entry in $(grep "rex login:" /var/log/foreman/production.log| tail -2| cut -d'"' -f30);do echo -e $entry| grep internal;done
fmtestvm3.internal, Mon Aug 15 14:53:04 UTC 2022
fmtestvm2.internal, Mon Aug 15 14:53:05 UTC 2022

Figure there is a smoother way though :slight_smile:
I see the “create report” button on the page you get to after I issue a command. No idea how to get the output from there though.

Hi,

I would assume this is exactly what you are looking for.
After hitting “gerate report”, you should be getting to a form something like this (this is a somewhat dated Foreman install, but should be similar) :


You basically just select your preferred format (csv, json, etc) and hit Submit. Once the report is generated (depending on your job, this can take a little while) you should be offered to download the report (my browser started the download automatically).
All the blank fields are basically optional. If you have any problems with this process, feel free to ask.
As far as I am aware of, this is the only “built in” method of getting something like what you are looking for. The only other way I am aware of would be scripting something yourself with hammer job-invocation getting the list of hosts from a show subcommand and then iterating over them with the output subcommand.

Reports should be the way to go.

Alternatively you could use the api if you really wanted and hit /api/v2/job_invocations/$ID/outputs?raw=1 where $ID is id of the job invocation, but that only gives you outputs and host ids, not names.

Tried the report button a few times, trying to make it send an email with the results but never arrived worked so never actually tried just create it as is, and of course it worked! I guess this report generated uses the “Job invocation - report template”? Wanted to customize the output a little on that report but looks like the template is locked. So not possible or?

This csv files, would have been nice to be able to pull it from from cli instead of gui, makes it a little simpler to automate and parse the result.

You can clone the locked template, edit the clone and then generate reports using the cloned template.