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
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:
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
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.
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.
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.
I run a custom remote execution job on multiple hosts but I don’t see any button to click on with “create report” or anything like that. Any clue (I’m on Foreman 3.13 - standalone no katello) ?
@jeremylenz Under Monitor > Reports > Report Templates, I see a list of report templates with a “Generate” button for each, but I don’t see “Job - Invocation Report”:
Is this perhaps a permissions issue? Unless you’ve deleted them, there should be dozens of default reports available. If you have access to log in as an admin user, does that help?
@jeremylenz Ok I found it! Thanks for your patience.
So the screenshots I shared in my previous post was on a “legacy” Foreman 3.13 that I didn’t configure and don’t know what went on there. However we also have a completely different instance of Foreman 3.17 where I do see the “Job - Invocatocation Report” template:
Ah, gotcha. The available reports will indeed be dictated by which Foreman plugins you have installed. The job invocation report is provided by the foreman_remote_execution plugin.
Yes, the foreman_remote_execution plugin version seems very old on the legacy Foreman, that could explain why the “Job - Invocation Report” template is missing there:
To serve my need I created a new custom report template which works well, my only remaining issue is that it’s somehow only visible to “admin” users, but that’s another topic.