Skip to content

Commit c6aa776

Browse files
authored
Disable Ansible debug mode for sub-commands (#284)
1 parent afd22be commit c6aa776

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/ansible_compat/runtime.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,10 @@ def run( # ruff: disable=PLR0913
327327
run_func: Callable[..., CompletedProcess] = subprocess_tee.run
328328
else:
329329
run_func = subprocess.run
330+
env = self.environ if env is None else env.copy()
331+
# Presence of ansible debug variable or config option will prevent us
332+
# from parsing its JSON output due to extra debug messages on stdout.
333+
env["ANSIBLE_DEBUG"] = "0"
330334

331335
for _ in range(self.max_retries + 1 if retry else 1):
332336
result = run_func(
@@ -335,12 +339,12 @@ def run( # ruff: disable=PLR0913
335339
check=False,
336340
stdout=subprocess.PIPE,
337341
stderr=subprocess.PIPE,
338-
env=env or self.environ,
342+
env=env,
339343
cwd=str(cwd) if cwd else None,
340344
)
341345
if result.returncode == 0:
342346
break
343-
_logger.debug("Environment: %s", env or self.environ)
347+
_logger.debug("Environment: %s", env)
344348
if retry:
345349
_logger.warning(
346350
"Retrying execution failure %s of: %s",

0 commit comments

Comments
 (0)