feat(ansible): run a playbook against a single Steward host (task 547)
CI / lint (push) Successful in 2s
CI / unit (push) Successful in 8s
CI / integration (push) Successful in 2m19s

From a host's edit page, an operator can run a playbook against just that host
via an ephemeral one-host inventory — no need for the host to exist in a source
inventory.

- ansible/sources.py: pure host_inventory_content(host) -> '<name> ansible_host=<addr>'
- executor.start_run: optional inventory_content written to the temp dir and used
  as -i (overrides inventory_path); cleaned up with the creds dir
- hosts/routes.py: POST /hosts/<id>/run-playbook (operator) — validates source +
  playbook, builds the ephemeral inventory, starts a user-triggered run, redirects
  to the live run detail; edit page gets the ansible source list
- hosts/form.html: 'Run Ansible playbook against this host' panel (shown when
  editing an existing host and sources exist) — source + playbook + extra-vars/
  tags/dry-run (no --limit; single host)
- tests: unit host_inventory_content; integration runs a hosts:all/connection:local
  playbook against the ephemeral inventory and asserts inventory_hostname

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-02 19:26:58 -04:00
parent 0bf007173b
commit 38f61b71c1
6 changed files with 233 additions and 4 deletions
+38
View File
@@ -49,5 +49,43 @@
</div>
</form>
</div>
{% if host and ansible_sources %}
<div class="card" style="margin-top:1.5rem;">
<h3 class="section-title" style="margin-bottom:0.5rem;">Run Ansible playbook against this host</h3>
<p style="color:var(--text-muted);font-size:0.82rem;margin-bottom:1rem;">
Runs against an ephemeral one-host inventory for
<code>{{ host.name }}</code> ({{ host.address or "no address — resolves by name" }}).
Use a playbook with <code>hosts: all</code>.
</p>
<form method="post" action="/hosts/{{ host.id }}/run-playbook">
<div class="form-group">
<label>Source</label>
<select name="source_name" required>
{% for s in ansible_sources %}<option value="{{ s }}">{{ s }}</option>{% endfor %}
</select>
</div>
<div class="form-group">
<label>Playbook <span style="color:var(--text-muted);font-weight:normal;">(path within source)</span></label>
<input type="text" name="playbook_path" placeholder="playbooks/site.yml" required>
</div>
<div class="form-group">
<label>Extra vars <span style="color:var(--text-muted);font-weight:normal;">(optional, one key=value per line)</span></label>
<textarea name="extra_vars" rows="2"
style="width:100%;font-family:ui-monospace,monospace;font-size:0.85rem;"></textarea>
</div>
<div class="form-group">
<label>Tags <span style="color:var(--text-muted);font-weight:normal;">(optional)</span></label>
<input type="text" name="tags">
</div>
<div class="form-group">
<label style="display:flex;align-items:center;gap:0.5rem;font-weight:normal;">
<input type="checkbox" name="check"> Dry-run (--check --diff)
</label>
</div>
<button type="submit" class="btn">Run playbook</button>
</form>
</div>
{% endif %}
</div>
{% endblock %}