Skip to content

Commit 0ad67a3

Browse files
committed
in 2.17+ prevent the callback from talking to stdout in forks
1 parent 401a77f commit 0ad67a3

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/ansible_runner/display_callback/callback/awx_display.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,12 @@
3434
from copy import copy
3535

3636
# Ansible
37+
from ansible import __version__ as ansible_version_str
3738
from ansible import constants as C
3839
from ansible.plugins.callback import CallbackBase
3940
from ansible.plugins.loader import callback_loader
4041
from ansible.utils.display import Display
42+
from ansible.utils.multiprocessing import context as multiprocessing_context
4143

4244

4345
DOCUMENTATION = '''
@@ -67,6 +69,9 @@
6769

6870
CENSORED = "the output has been hidden due to the fact that 'no_log: true' was specified for this result"
6971

72+
_ANSIBLE_VERSION = tuple(int(p) for p in ansible_version_str.split('.')[:2])
73+
_ANSIBLE_217 = _ANSIBLE_VERSION >= (2, 17)
74+
7075

7176
def current_time():
7277
return datetime.datetime.now(datetime.timezone.utc)
@@ -282,10 +287,18 @@ def wrapper(*args, **kwargs):
282287
Display.verbose = with_verbosity(Display.verbose)
283288

284289

290+
@functools.lru_cache(maxsize=2)
291+
def _is_child():
292+
return multiprocessing_context.parent_process() is not None
293+
294+
285295
def display_with_context(f):
286296

287297
@functools.wraps(f)
288298
def wrapper(*args, **kwargs):
299+
if _ANSIBLE_217 and _is_child():
300+
return f(*args, **kwargs)
301+
289302
log_only = args[5] if len(args) >= 6 else kwargs.get('log_only', False)
290303
stderr = args[3] if len(args) >= 4 else kwargs.get('stderr', False)
291304
event_uuid = event_context.get().get('uuid', None)

0 commit comments

Comments
 (0)