You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
however, according to this #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
The text was updated successfully, but these errors were encountered:
I found a very ugly way to achieve this but I do not know if this is stable or just a side effect:
def my_stdout(stdout: str, res: dict):
remove_large_res = re.compile(r"( => )\{.*\}")
neg_keys = [
'stdout_lines', 'stderr_lines',
'start', 'end', 'delta',
'invocation',
# '_ansible_no_log',
# "_ansible_item_label"
]
data = {k:v for k, v in res.items() if k not in neg_keys and not k.startswith('_')}
_dump = r'\1\n' + yaml.safe_dump(data)
return remove_large_res.sub(_dump, stdout)
def handle_event(event):
# Format event as YAML
if event['event'].endswith("_failed") and 'event_data' in event:
event_data = event['event_data']
host = event_data["host"]
# remove stderrlines and stderrouts
if 'res' in event_data:
keys_to_remove = ['stdout_lines', 'stderr_lines']
for k in keys_to_remove:
if k in event_data['res']:
event_data['res'].pop(k)
event['stdout'] =my_stdout(event['stdout'], event_data['res'])
return True
this depends on the fact that handle_event() can actually modify the event, is this a stable feature?
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:
however, according to this #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
The print out can happen any time not synced with the normal output
The text was updated successfully, but these errors were encountered: