aoh

A tool for running Ansible playbooks with `curl <url> | python` commands
git clone https://git.ashermorgan.net/aoh/
Log | Files | Refs | README

commit f7da3d7c2877d87ce3c9db091e00dd8bf553f679
parent 4ad640c3f5948ce279908e12578a30e56b51bf64
Author: Asher Morgan <asher@ashermorgan.net>
Date:   Sat, 15 Aug 2026 19:59:37 -0700

Fix linter errors

Diffstat:
Mconnection_plugins/http.py | 20++++++++------------
Minstall.py | 7+++----
Mmain.py | 15+++++++--------
3 files changed, 18 insertions(+), 24 deletions(-)

diff --git a/connection_plugins/http.py b/connection_plugins/http.py @@ -1,5 +1,3 @@ -#!/usr/bin/python - # Copyright: (c) 2026, Asher Morgan <asher@ashermorgan.net> # GNU General Public License v3.0+ @@ -15,16 +13,14 @@ DOCUMENTATION = r''' - name: ansible_http_runner ''' -# ruff: disable[E402] import base64 import json import os import typing as t -from ansible.errors import AnsibleFileNotFound, AnsibleError +from ansible.errors import AnsibleError, AnsibleFileNotFound from ansible.plugins.connection import ConnectionBase from ansible.utils.display import Display -# ruff: enable[E402] display = Display() @@ -37,7 +33,7 @@ class Connection(ConnectionBase): def __init__(self, *args: t.Any, **kwargs: t.Any) -> None: - super(Connection, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) self.sendbuf = None self.recvbuf = None @@ -59,8 +55,8 @@ class Connection(ConnectionBase): if not os.path.exists(SENDBUF_PATH): os.mkfifo(SENDBUF_PATH) - self.recvbuf = open(RECVBUF_PATH, 'r') - self.sendbuf = open(SENDBUF_PATH, 'w') + self.recvbuf = open(RECVBUF_PATH, 'r') # noqa: SIM115 + self.sendbuf = open(SENDBUF_PATH, 'w') # noqa: SIM115 self._connected = True @@ -71,7 +67,7 @@ class Connection(ConnectionBase): sudoable: bool = True) -> tuple[int, bytes, bytes]: """Run a command on the host.""" - super(Connection, self).exec_command(cmd, in_data=in_data, sudoable=sudoable) + super().exec_command(cmd, in_data=in_data, sudoable=sudoable) display.vvv(f'EXEC {cmd}', host=self._play_context.remote_addr) @@ -99,7 +95,7 @@ class Connection(ConnectionBase): def put_file(self, in_path: str, out_path: str) -> None: """Transfer file to host.""" - super(Connection, self).put_file(in_path, out_path) + super().put_file(in_path, out_path) display.vvv(f'PUT {in_path} TO {out_path}', host=self._play_context.remote_addr) @@ -128,7 +124,7 @@ class Connection(ConnectionBase): def fetch_file(self, in_path: str, out_path: str) -> None: """Fetch file from host.""" - super(Connection, self).fetch_file(in_path, out_path) + super().fetch_file(in_path, out_path) display.vvv(f'FETCH {in_path} TO {out_path}', host=self._play_context.remote_addr) @@ -162,4 +158,4 @@ class Connection(ConnectionBase): self._connected = False - super(Connection, self).close() + super().close() diff --git a/install.py b/install.py @@ -6,7 +6,6 @@ import time import requests # TODO: eliminate dependency? - API = 'http://localhost:5000' @@ -25,7 +24,7 @@ def exec(args): 'stdout': stdout.decode('latin1'), 'stderr': stderr.decode('latin1'), } - except Exception as e: + except Exception as e: # noqa: BLE001 return { 'err': str(e) } @@ -33,7 +32,7 @@ def put(args): try: with open(args['dest'], 'wb') as f: f.write(base64.b64decode(args['data'])) - except Exception as e: + except Exception as e: # noqa: BLE001 return { 'err': str(e) } else: return { 'ok': True } @@ -45,7 +44,7 @@ def fetch(args): return { 'data': base64.b64encode(f.read()).decode(), } - except Exception as e: + except Exception as e: # noqa: BLE001 return { 'err': str(e) } diff --git a/main.py b/main.py @@ -1,13 +1,12 @@ -import time import json import os import shutil import tempfile +import time +from uuid import uuid4 import ansible_runner from flask import Flask, abort, make_response, request, send_file, session -from uuid import uuid4 - DATA = {} PLAYBOOK = os.path.abspath('./demo/playbook.yml') # TODO @@ -36,7 +35,7 @@ class Runner: # We assume that ansible-runner will eventually create its log file while not os.path.exists(self._LOGS_PATH): time.sleep(0.1) - self._logs = open(self._LOGS_PATH, 'r') + self._logs = open(self._LOGS_PATH, 'r') # noqa: SIM115 # The FIFO buffers may not get created if Ansible crashes/exits # before calling the http connection plugin @@ -45,8 +44,8 @@ class Runner: time.sleep(0.1) if os.path.exists(self._RECVBUF_PATH): # Note that recvbuf is created first, so sendbuf will exist too - self._recvbuf = open(self._RECVBUF_PATH, 'w') - self._sendbuf = open(self._SENDBUF_PATH, 'r') + self._recvbuf = open(self._RECVBUF_PATH, 'w') # noqa: SIM115 + self._sendbuf = open(self._SENDBUF_PATH, 'r') # noqa: SIM115 except: self.teardown() raise @@ -56,10 +55,10 @@ class Runner: raw_config = ansible_runner.get_ansible_config('dump', config, quiet=True)[0] - connection_plugins = eval([ + connection_plugins = eval(next( x for x in raw_config.split('\n') if x.startswith('DEFAULT_CONNECTION_PLUGIN_PATH') - ][0].split('= ')[1]) + ).split('= ')[1]) env = { 'ANSIBLE_CONNECTION_PLUGINS': ':'.join(