1

Is there a way to separate by host the output from a multi fork ad-hoc command?

I.e., if I ran:

ansible <group> -a '/some/cmd' -f 2

The result comes back as one long stream like

host1 | CHANGED | rc=0 >>
Listing...
"some output"
host2 | CHANGED | rc=0 >>
Listing...
"other output"

For clarity I would prefer the output with a gap between the output from each host like:

host1 | CHANGED | rc=0 >>
Listing...
"some output"

host2 | CHANGED | rc=0 >>
Listing...
"other output"

Even creating a script on the target that does an echo at the end and running that doesn't do it.

U880D
  • 8,601
  • 6
  • 24
  • 40
  • 5
    There's no easy way to do what you're asking. You could probably write a [callback plugin](https://docs.ansible.com/ansible/latest/plugins/callback.html) to do what you want, but that's a big hammer. If you want to generate a human-readable report, consider writing a playbook and generating the report with the `template` module. – larsks Jul 28 '21 at 23:14

1 Answers1

1

I've experienced the same behavior that empty lines at the end gets removed. Since I have a similar requirement sometimes and depending on the task, I use the following approach

ansible test --user ${USER} --ask-pass --module-name shell --args "echo 'Output format test'; echo ' ';"

resulting in an output of

test1.example.com | CHANGED | rc=0 >>
Output format test

test2.example.com | CHANGED | rc=0 >>
Output format test
    

In other words, just add an ; echo ' '; at the end.

Further information regarding output formatting can be found under

U880D
  • 8,601
  • 6
  • 24
  • 40