aoh

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

commit 72277aa96ab12512fa01214ea9c75699452166ed
parent 51d38d98b6de99c5f6a990212f989a22fab4eed6
Author: Asher Morgan <asher@ashermorgan.net>
Date:   Sat, 29 Aug 2026 19:41:13 -0700

Include playbook path in API routes

Diffstat:
Maoh/client.py | 3+--
Maoh/server.py | 31++++++++++++++++---------------
2 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/aoh/client.py b/aoh/client.py @@ -142,11 +142,10 @@ def runner_loop(runner_url, cookies): def create_runner(playbook, args): """Main execution loop.""" - url = f'{API}/runners/' + url = f'{API}/runners/{playbook}' req = { 'host': platform.node(), - 'playbook': playbook, 'args': args, } diff --git a/aoh/server.py b/aoh/server.py @@ -1,6 +1,6 @@ import os -from flask import Flask, make_response, render_template, request, session +from flask import Flask, render_template, request, session from flask_apscheduler import APScheduler from .playbook import get_playbook @@ -35,11 +35,11 @@ def install(): return render_template('client.py', API_URL=api_url) -@app.post('/runners/') -def new_runner(): - playbook = get_playbook(request.json['playbook']) +@app.post('/runners/<path:path>') +def new_runner(path): + playbook = get_playbook(path) if not playbook: - return { 'err': f"Playbook not found: {request.json['playbook']}" }, 400 + return { 'err': f"Playbook not found: {path}" }, 400 if not validate_args(playbook, request.json['args']): return { 'err': 'Bad or banned arguments passed.' }, 400 @@ -61,24 +61,25 @@ def new_runner(): runner = Runner(playbook, request.json['host'], request.json['args'], act_pws) + assert runner.id is not None _RUNNERS[runner.id] = runner session['runner'] = runner.id + short_id = runner.id.split('-')[0] - return make_response({}, 201, {'Location': f'/runners/{runner.id}'}) + return {}, 201, {'Location': f'/runners/{path}/{short_id}'} -@app.put('/runners/<id>') -def runner_update(id): - if id != session.get('runner'): - return make_response({ - 'err': 'Invalid runner ID', - }, 401) +@app.put('/runners/<path:path>/<short_id>') +def runner_update(path, short_id): + id = session.get('runner') + if not id or not id.startswith(short_id): + return { 'err': 'Invalid runner ID' }, 401 runner = _RUNNERS.get(id) if not runner: - return make_response({ - 'err': 'Runner not found', - }, 404) + return { 'err': 'Runner not found' }, 404 + if runner.playbook.name != path: + return { 'err': f"Playbook not found: {path}" }, 400 res = runner.process_client_request(request.json)