commit eecaa960aa67a1021e620744be6d2482a56c2222
parent 4501d092149170843b3241378fe772176f219391
Author: Asher Morgan <asher@ashermorgan.net>
Date: Thu, 3 Sep 2026 19:23:20 -0700
Add pipelining support
Diffstat:
2 files changed, 18 insertions(+), 9 deletions(-)
diff --git a/aoh/client.py b/aoh/client.py
@@ -28,26 +28,30 @@ class ClientError(Exception):
"""Raised for miscellaneous client errors."""
-def exec(args, keep_alive_interval=None, keep_alive_handler=None):
+def exec(args, keep_alive_interval, keep_alive_handler):
"""Run a command on the local host."""
try:
p = subprocess.Popen(
- args,
+ args['cmd'],
shell=True,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
+ stdin = args['stdin']
+ if stdin is not None:
+ stdin = stdin.encode('latin1')
+
while p.returncode is None:
try:
- p.wait(keep_alive_interval)
+ stdout, stderr = p.communicate(input=stdin,
+ timeout=keep_alive_interval)
except subprocess.TimeoutExpired:
- if keep_alive_handler:
- keep_alive_handler()
+ keep_alive_handler()
+ stdin = None # Don't send input a second time
- stdout, stderr = p.communicate()
return {
'returncode': p.returncode,
'stdout': stdout.decode('latin1'),
diff --git a/aoh/connection_plugins/aoh.py b/aoh/connection_plugins/aoh.py
@@ -58,7 +58,8 @@ class Connection(ConnectionBase):
"""Ansible-over-HTTP (AoH) connection."""
transport = 'aoh'
- has_pipelining = False
+ has_pipelining = True
+ has_tty = False
def __init__(self, *args: t.Any, **kwargs: t.Any) -> None:
@@ -157,9 +158,13 @@ class Connection(ConnectionBase):
display.vvv(f'EXEC {cmd}', host=self._play_context.remote_addr)
assert isinstance(cmd, str)
- assert in_data is None
- res = self._send_message({ 'exec': cmd })
+ res = self._send_message({
+ 'exec': {
+ 'cmd': cmd,
+ 'stdin': in_data and in_data.decode('latin1'),
+ },
+ })
if not all(k in res for k in ['returncode', 'stdout', 'stderr']):
raise AnsibleError('Received invalid AoH EXEC response')
return (