From 2d85b5e58fa2516f60af6bb30e96484545f381bd Mon Sep 17 00:00:00 2001 From: Vincent Capelle Date: Sun, 3 Mar 2024 19:47:34 -0500 Subject: [PATCH] Set ANSIBLE_FORCE_COLOR sooner to fix missing color output in tmux --- src/molecule/console.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/molecule/console.py b/src/molecule/console.py index f7f56864ae..d06d947a00 100644 --- a/src/molecule/console.py +++ b/src/molecule/console.py @@ -72,6 +72,12 @@ def should_do_markup() -> bool: return sys.stdout.isatty() +# Define ANSIBLE_FORCE_COLOR if markup is enabled and another value is not +# already given. This assures that Ansible subprocesses are still colored, +# even if they do not run with a real TTY. +if should_do_markup(): + os.environ["ANSIBLE_FORCE_COLOR"] = os.environ.get("ANSIBLE_FORCE_COLOR", "1") + console_options: dict[str, Any] = {"emoji": False, "theme": theme, "soft_wrap": True} console = Console( @@ -83,9 +89,3 @@ def should_do_markup() -> bool: console_options_stderr = console_options.copy() console_options_stderr["stderr"] = True console_stderr: Console = Console(**console_options_stderr) - -# Define ANSIBLE_FORCE_COLOR if markup is enabled and another value is not -# already given. This assures that Ansible subprocesses are still colored, -# even if they do not run with a real TTY. -if should_do_markup(): - os.environ["ANSIBLE_FORCE_COLOR"] = os.environ.get("ANSIBLE_FORCE_COLOR", "1")