pyinfra icon indicating copy to clipboard operation
pyinfra copied to clipboard

Combined output for facts with custom success codes

Open mohsinhijazee opened this issue 3 years ago • 0 comments

Problem

Currently, when getting facts, only the stdout is returned in case of success. Now beccause we support success_exit_codes in fact fetching like this after #755:

from pyinfra import facts, host

fact = host.get_fact(
    facts.server.Command,
    "somefailingcommand",
    success_exit_codes=[0, 27, 55])

# Now fact only contains stdout and won't contain stderr. 

The fact only has stdout but becuse the "succuess" was kind hacked by suggesting a list of OK codes, the only stdout is returned but the actualy output of the command is on stderr which is igonred.

Possible solutions

One possible solution is to add something like returned_combined_output kind of keyword argument that combines stdout and stderr regardless of the status code. That would require changes in pyinfra itself.

Other workaround is to issue your shell commands like this by redirecting and combining stdout and stderr together:

somefailingcommand 2>&1

I am not sure, open to ideas and suggestions.

mohsinhijazee avatar Feb 18 '22 14:02 mohsinhijazee