commit ebbefecb220c420f638e0194e398bf5b56e6c8c3
parent 70195283098182a67a4c2ed5ae01152d1b2c7734
Author: Asher Morgan <asher@ashermorgan.net>
Date: Fri, 18 Sep 2026 16:55:26 -0700
Add support for en/disabling colored output
Diffstat:
3 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/aoh/client.py b/aoh/client.py
@@ -265,9 +265,16 @@ def create_runner(playbook, args):
url = f'{AOH_ORIGIN}/runners/{playbook}'
+ TRUTHY_VALUES = ['1', 'true', 'yes']
+ color = sys.stdout.isatty()
+ color &= os.getenv('NO_COLOR', '').lower() not in TRUTHY_VALUES
+ color &= os.getenv('ANSIBLE_NOCOLOR', '').lower() not in TRUTHY_VALUES
+ color |= os.getenv('ANSIBLE_FORCE_COLOR', '').lower() in TRUTHY_VALUES
+
req = {
'host': platform.node(),
'args': args,
+ 'color': color,
}
status, headers, res = send_json_request(url, req, 'POST')
diff --git a/aoh/runner.py b/aoh/runner.py
@@ -55,13 +55,14 @@ def get_config_values(config, keys):
class Runner:
"""An Ansible-over-HTTP playbook runner."""
- def __init__(self, playbook, host, args, passwords):
+ def __init__(self, playbook, host, args, color, passwords):
"""Create a new AoH runner."""
self.id = str(uuid.uuid4()) # Runner ID (set to None after teardown)
self.playbook = playbook
self.host = self.playbook.host or host or 'aoh_node'
self.args = args
+ self.color = color
self.passwords = passwords
self._lock = threading.Lock() # Used to protect all public methods
@@ -117,7 +118,7 @@ class Runner:
config['DEFAULT_CONNECTION_PLUGIN_PATH']
),
'ANSIBLE_CONFIG': self.playbook.config,
- 'ANSIBLE_FORCE_COLOR': '1',
+ ('ANSIBLE_FORCE_COLOR' if self.color else 'NO_COLOR'): '1',
'ANSIBLE_INVENTORY': ','.join(
[f'{self._DIR}/inventory.ini'] + config['DEFAULT_HOST_LIST']
),
diff --git a/aoh/server.py b/aoh/server.py
@@ -102,7 +102,7 @@ def new_runner(path):
return {'err': 'Bad or banned arguments passed'}, 400
runner = Runner(playbook, request.json['host'], request.json['args'],
- act_pws)
+ request.json['color'], act_pws)
assert runner.id is not None
_RUNNERS[runner.id] = runner