To simplify printing shell output in many simple situations, I'd like a quick Ansible Playbook snippet to show just the stdout_lines and stderr_lines — but still keeping them distinct.
- name: demo output streams
shell: "echo hi stdout; echo ho stderr 1>&2; false; true"
register: tout
- debug:
var: tout
gives this:
TASK [debug] **************************************************************
ok: [remote] => {
"tout": {
"changed": true,
"cmd": "echo hi stdout; echo ho stderr 1>&2; false; true",
"delta": "0:00:00.011020",
"end": "2022-02-24 16:19:25.812732",
"failed": false,
"msg": "",
"rc": 0,
"start": "2022-02-24 16:19:25.801712",
"stderr": "ho stderr",
"stderr_lines": [
"ho stderr"
],
"stdout": "hi stdout",
"stdout_lines": [
"hi stdout"
]
}
}
What I want is something more concise like this, or perhaps split, but still referenced by a single debug task in the Playbook. (Integrated into the shell task itself would be even more ideal, but I guess that's off the table.)
TASK [debug] **************************************************************
ok: [remote] => {
"tout": {
"stderr_lines": [
"ho stderr"
],
"stdout_lines": [
"hi stdout"
]
}
}
The false and true fluff just indicates that I simply want to see the command outputs, without Ansible-worrying about success or failure.
Of course I could use multiple debug's, but that output becomes cumbersome when there are many of these quick-info tasks.