ansible-runner
ansible-runner copied to clipboard
is there away to control ansible stdout output?
we normally use the yaml or the diy callback for stdout, this make the large failure message far more readable on the fly. The json mode put the output the dict on single line, which is hard to read when the dict contains multiline strings
for example:
fatal: [localhost]: FAILED! => {"changed": false, "cmd": "set -e\nset -x\necho hello\nexit 1\n", "delta": "0:00:00.002386", "end": "2024-08-14 22:34:33.969828", "msg": "non-zero return code", "rc": 1, "start": "2024-08-14 22:34:33.967442", "stderr": "+ echo hello\n+ exit 1", "stderr_lines": ["+ echo hello", "+ exit 1"], "stdout": "hello", "stdout_lines": ["hello"]}
however, according to this https://github.com/ansible/ansible-runner/issues/212, it prevent us to change the stdout_callback
I wonder is there a way to tune the stdout in the way we wanted with ansible-runner?
I try to use event_handler but it won't sync with the playbook screen output
def handle_event(event):
if event['event'] == "runner_on_failed" and 'event_data' in event:
event_data = event['event_data']
keys = ["task_path", 'res']
data = {k:event_data[k] for k in keys if k in event_data}
if data:
print(yaml.safe_dump(data, default_flow_style=False))
The print out can happen any time not synced with the normal output