Is there a way to capture the stdout and stderr separately in bash, maybe as a tuple, for ansible ad-hoc commands? Something like: stdout, stderr= ansible -i hosts -m shell -a "command"
Asked
Active
Viewed 395 times
0

QuantAC
- 31
- 1
- 9
-
Could you be more specific what is desired output of what command? You can use grep or sed to redirect stdout and stderr to proper log file. – 32cupo Apr 14 '20 at 12:28
1 Answers
0
You could use option -t
to log output in JSON format. For example if I execute
ansible -m shell -a "echo test" -t tmp localhost
then in the file ./tmp/localhost
I'll get this output:
{
"changed": true,
"cmd": "echo test",
"delta": "0:00:00.006099",
"end": "2020-04-14 11:43:01.878959",
"rc": 0,
"start": "2020-04-14 11:43:01.872860",
"stderr": "",
"stderr_lines": [],
"stdout": "test",
"stdout_lines": [
"test"
]
}
You can then parse stdout and stderr.

rolf82
- 1,531
- 1
- 5
- 15