feat(ui): each run says who or what started it; run detail without ids (#5212)
CI / lint (push) Successful in 2s
CI / integration (push) Successful in 49s
CI / unit (push) Successful in 1m15s
CI / publish (push) Successful in 1m3s

#5212 "Plain labels: no raw ids, scopes, metric keys or unexplained jargon",
batch 2:

- A run records where it came from: AnsibleRun.origin ("schedule", "alert"
  or "mcp") and origin_id, set by the scheduler, Run now, alert actions and
  the MCP tools. Migration 0031 backfills past runs from alert events,
  schedules' last runs, and MCP audit entries.
- The runs list has a Started by column: "schedule nightly", "alert rule
  nas down", "alice via MCP" or "alice", linked where there is a page.
  The raw scope tooltip is gone.
- Run detail: no run id in the subtitle or body, Started by in words, and
  the host summary lists failed and unreachable hosts first. The live
  output only follows new lines while the reader is at the bottom, and
  when the run finishes the page reloads once so the badge and summary
  are final.
- list_ansible_runs and get_ansible_run report origin and origin_id.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-07 00:26:17 -04:00
co-authored by Claude Opus 5.5
parent a96112a0e1
commit e780932673
14 changed files with 192 additions and 27 deletions
+4 -3
View File
@@ -5,17 +5,18 @@
{% set run = row.run %}
<tr>
<td>
<a href="/ansible/runs/{{ run.id }}" title="{{ run.inventory_scope }}">{{ row.title }}</a>
<a href="/ansible/runs/{{ run.id }}">{{ row.title }}</a>
{% if row.check %}<span class="badge badge-dim" title="Ansible check mode: nothing was changed">dry run</span>{% endif %}
<div class="field-hint">{{ run.source_name }}</div>
</td>
<td>{{ status_badge(run.status) }}</td>
<td style="font-size:0.85rem;">{% if row.origin %}{% if row.origin.url %}<a href="{{ row.origin.url }}">{{ row.origin.text }}</a>{% else %}{{ row.origin.text }}{% endif %}{% endif %}</td>
<td title="{{ run.started_at.strftime('%Y-%m-%d %H:%M:%S UTC') }}">{{ run.started_at|ago }}</td>
<td>{{ row.duration_s|duration }}{% if not run.finished_at and run.status.value in ('running', 'queued') %} so far{% endif %}</td>
</tr>
{% endfor %}
{% if after %}
{{ scroll_more("/ansible/?before=" ~ (after|urlencode), cols=4) }}
{{ scroll_more("/ansible/?before=" ~ (after|urlencode), cols=5) }}
{% else %}
{{ scroll_end(cols=4) }}
{{ scroll_end(cols=5) }}
{% endif %}
+1
View File
@@ -16,6 +16,7 @@
<tr>
<th>Run</th>
<th>Status</th>
<th>Started by</th>
<th>Started</th>
<th>Duration</th>
</tr>
+18 -7
View File
@@ -3,7 +3,7 @@
{% block title %}{{ row.title }} — Steward{% endblock %}
{% block breadcrumb %}{{ crumbs([("Ansible", "/ansible/"), (row.title, "")]) }}{% endblock %}
{% block content %}
{% call page_header(row.title, "Run " ~ run.id[:8] ~ " from " ~ run.source_name) %}
{% call page_header(row.title, "From the " ~ run.source_name ~ " playbook source") %}
{% if run.status.value in ("running", "queued") and session.user_role in ("operator", "admin") %}
<form method="post" action="/ansible/runs/{{ run.id }}/cancel" data-confirm="Cancel this run?">{{ csrf_field() }}
<button type="submit" class="btn btn-sm btn-danger">Cancel run</button>
@@ -20,17 +20,16 @@
<dt>Playbook</dt><dd>{{ run.playbook_path }}</dd>
<dt>Scope</dt><dd title="{{ run.inventory_scope }}">{{ row.scope_label }}</dd>
<dt>Source</dt><dd>{{ run.source_name }}</dd>
<dt>Triggered by</dt><dd>{{ triggered_label }}</dd>
<dt>Started by</dt><dd>{% if origin.url %}<a href="{{ origin.url }}">{{ origin.text }}</a>{% else %}{{ origin.text }}{% endif %}</dd>
{% if run.params %}
{% if run.params.limit %}<dt>Limit</dt><dd class="mono">{{ run.params.limit }}</dd>{% endif %}
{% if run.params.tags %}<dt>Tags</dt><dd class="mono">{{ run.params.tags }}</dd>{% endif %}
{% if run.params.extra_vars %}<dt>Extra vars</dt><dd class="mono">{{ run.params.extra_vars | join(", ") }}</dd>{% endif %}
{% endif %}
<dt>ID</dt><dd class="mono field-hint">{{ run.id }}</dd>
</dl>
</div>
{% if run.results and run.results.hosts %}
{% if hosts %}
<div class="card">
<div class="section-title" style="margin-bottom:0.6rem;">Host summary</div>
<table class="table">
@@ -41,7 +40,7 @@
<th style="text-align:center;">skipped</th>
</tr></thead>
<tbody>
{% for host, c in run.results.hosts.items() %}
{% for host, c in hosts %}
<tr>
<td style="font-family:ui-monospace,monospace;">{{ host }}</td>
<td style="text-align:center;">{{ c.ok }}</td>
@@ -75,13 +74,25 @@
var es = new EventSource('/ansible/runs/{{ run.id }}/stream');
var pre = document.getElementById('live-output');
var status = document.getElementById('run-done-status');
// Follow new lines only while the reader is at the bottom; scrolled
// up to read something, they keep their place.
es.addEventListener('output', function(e) {
var atBottom = pre.scrollHeight - pre.scrollTop - pre.clientHeight < 24;
pre.textContent += e.data + '\n';
pre.scrollTop = pre.scrollHeight;
if (atBottom) pre.scrollTop = pre.scrollHeight;
});
// Finished: load the page again, so the status, duration and host
// summary are the run's final ones rather than "Running". The
// executor saves the final status before it says done; should that
// save have failed, ?finished stops a second reload going round.
es.addEventListener('done', function(e) {
es.close();
status.textContent = 'Finished: ' + e.data;
if (window.location.search.indexOf('finished=1') === -1) {
status.textContent = 'Finished. Loading the summary…';
window.location.replace(window.location.pathname + '?finished=1');
} else {
status.textContent = 'Finished (' + e.data + '), but the summary could not be saved.';
}
});
})();
</script>