Files
FabledSteward/steward/templates/hosts/form.html
T
bvandeusen 38f61b71c1
CI / lint (push) Successful in 2s
CI / unit (push) Successful in 8s
CI / integration (push) Successful in 2m19s
feat(ansible): run a playbook against a single Steward host (task 547)
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>
2026-06-02 19:26:58 -04:00

92 lines
4.7 KiB
HTML

{% extends "base.html" %}
{% block title %}{% if host %}Edit Host{% else %}New Host{% endif %} — Steward{% endblock %}
{% block content %}
<div style="max-width:560px;margin:2rem auto;">
<h1 class="page-title">{% if host %}Edit Host{% else %}Add Host{% endif %}</h1>
<div class="card">
<form method="post" action="{% if host %}/hosts/{{ host.id }}{% else %}/hosts/{% endif %}">
<div class="form-group">
<label>Display Name</label>
<input type="text" name="name" value="{{ host.name if host else '' }}" required autofocus>
</div>
<div class="form-group">
<label>Address (hostname or IP)</label>
<input type="text" name="address" value="{{ host.address if host else '' }}" required>
</div>
<div class="form-group">
<label>Probe Type</label>
<select name="probe_type">
{% for pt in probe_types %}
<option value="{{ pt.value }}" {% if host and host.probe_type == pt %}selected{% endif %}>
{{ pt.value | upper }}
</option>
{% endfor %}
</select>
</div>
<div class="form-group">
<label>TCP Port (used for TCP probe; ignored for ICMP)</label>
<input type="number" name="probe_port" value="{{ host.probe_port if host else 80 }}" min="1" max="65535">
</div>
<div class="form-group">
<label style="display:flex;align-items:center;gap:0.5rem;cursor:pointer;">
<input type="checkbox" name="ping_enabled" {% if not host or host.ping_enabled %}checked{% endif %}>
Enable ping monitor
</label>
</div>
<div class="form-group">
<label style="display:flex;align-items:center;gap:0.5rem;cursor:pointer;">
<input type="checkbox" name="dns_enabled" {% if host and host.dns_enabled %}checked{% endif %}>
Enable DNS monitor
</label>
</div>
<div class="form-group">
<label>Expected IP (optional — leave blank to accept any)</label>
<input type="text" name="dns_expected_ip" value="{{ host.dns_expected_ip if host and host.dns_expected_ip else '' }}">
</div>
<div style="display:flex;gap:1rem;margin-top:1.5rem;">
<button type="submit" class="btn">{% if host %}Save{% else %}Add Host{% endif %}</button>
<a href="/hosts/" class="btn btn-ghost">Cancel</a>
</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 %}