- One run per host: start_run claims every host it touches (addresses read from the inventory Steward wrote; a source's own inventory file is claimed as that file) before it takes a run slot. The claim is all-or-nothing. A run waiting on a host shows queued and names the run it waits for, honours a cancel, and fails after HOST_WAIT_SECONDS (1 h) with which host and run. - A due schedule whose previous run is still queued or running skips the firing: last_run_at moves on, last_run_id still names the run going, and last_error says "Skipped: the previous run was still going". The Schedules page shows that beside the run (muted), and a launch error in red. - An alert rule that fires while the action run from an earlier firing is still going starts no new run; the event says so and names the run. An in-process set closes the gap between the check and the run being linked. - docs/core/ansible.md: queued/cancelled statuses and the overlap rules. Tests: tests/core/test_ansible_overlap.py (claim keys, waiting, all-or-nothing, cancel, deadline) and tests/integration/test_ansible_overlap.py (two real runs on one host take turns; schedule skip then fire; alert action skip then start). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
179 lines
9.4 KiB
HTML
179 lines
9.4 KiB
HTML
{% extends "base.html" %}
|
|
{% from "_macros.html" import crumbs %}
|
|
{% block title %}Ansible Schedules — Steward{% endblock %}
|
|
{% block breadcrumb %}{{ crumbs([("Ansible", "/ansible/"), ("Schedules", "")]) }}{% endblock %}
|
|
|
|
{% macro fmt_interval(secs) %}
|
|
{%- set m = {300: "every 5 min", 3600: "hourly", 21600: "every 6h", 43200: "every 12h", 86400: "daily", 604800: "weekly"} -%}
|
|
{{ m.get(secs, secs ~ "s") }}
|
|
{% endmacro %}
|
|
|
|
{% block content %}
|
|
<div style="display:flex;align-items:center;justify-content:space-between;margin-bottom:1.25rem;gap:1rem;flex-wrap:wrap;">
|
|
<h1 class="page-title" style="margin-bottom:0;">Ansible Schedules</h1>
|
|
<div style="display:flex;gap:0.5rem;">
|
|
<a href="/ansible/inventory/targets" class="btn btn-ghost">Inventory</a>
|
|
<a href="/ansible/browse" class="btn btn-ghost">Browse</a>
|
|
</div>
|
|
</div>
|
|
|
|
{# ── Existing schedules ───────────────────────────────────────────────────── #}
|
|
{% if not rows %}
|
|
<div class="card empty">No schedules yet. Create one below to run a playbook on a recurring interval.</div>
|
|
{% else %}
|
|
<div class="card-flush">
|
|
<table class="table">
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th><th>Playbook</th><th>Target</th><th>Interval</th>
|
|
<th>Last run</th><th>Next run</th><th></th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
{% for row in rows %}
|
|
{% set s = row.s %}
|
|
<tr style="{% if not s.enabled %}opacity:0.55;{% endif %}">
|
|
<td style="font-weight:500;">{{ s.name }}</td>
|
|
<td style="font-size:0.85rem;"><span style="color:var(--text-dim);">{{ s.source_name }}</span> / {{ s.playbook_path }}</td>
|
|
<td style="font-size:0.85rem;" title="{{ s.inventory_scope }}">{{ row.scope_label }}</td>
|
|
<td style="font-size:0.85rem;">{{ fmt_interval(s.interval_seconds) }}</td>
|
|
<td style="font-size:0.82rem;">
|
|
{% if row.last_run %}
|
|
{% set sc = {"queued":"var(--text-dim)","running":"var(--yellow)","success":"var(--green)","failed":"var(--red)","interrupted":"var(--orange)","cancelled":"var(--orange)"}.get(row.last_run.status.value, "var(--text-muted)") %}
|
|
<a href="/ansible/runs/{{ row.last_run.id }}" style="color:{{ sc }};font-weight:500;">{{ row.last_run.status.value }}</a>
|
|
<span style="color:var(--text-dim);">· {{ row.last_run.started_at.strftime("%m-%d %H:%M") }}</span>
|
|
{% endif %}
|
|
{% if s.last_error %}
|
|
{# With a run beside it, the last firing was skipped because that run was
|
|
still going (#5158); without one, the firing couldn't start a run. #}
|
|
<div style="color:{{ 'var(--text-muted)' if row.last_run else 'var(--red)' }};">
|
|
{{ s.last_error }} · {{ s.last_run_at.strftime("%m-%d %H:%M") }}
|
|
</div>
|
|
{% elif not row.last_run %}
|
|
<span style="color:var(--text-dim);">never</span>
|
|
{% endif %}
|
|
</td>
|
|
<td style="font-size:0.82rem;color:var(--text-muted);">
|
|
{% if not s.enabled %}<span style="color:var(--text-dim);">paused</span>
|
|
{% elif row.next_run %}{{ row.next_run.strftime("%m-%d %H:%M") }}
|
|
{% else %}due now{% endif %}
|
|
</td>
|
|
<td class="td-actions" style="white-space:nowrap;">
|
|
<form method="post" action="/ansible/schedules/{{ s.id }}/run-now" style="display:inline;">{{ csrf_field() }}
|
|
<button class="btn btn-sm btn-ghost" type="submit">Run now</button>
|
|
</form>
|
|
<form method="post" action="/ansible/schedules/{{ s.id }}/toggle" style="display:inline;">{{ csrf_field() }}
|
|
<button class="btn btn-sm btn-ghost" type="submit">{{ "Pause" if s.enabled else "Resume" }}</button>
|
|
</form>
|
|
<a href="?edit={{ s.id }}#form" class="btn btn-sm btn-ghost">Edit</a>
|
|
<form method="post" action="/ansible/schedules/{{ s.id }}/delete" style="display:inline;"
|
|
data-confirm="Delete schedule {{ s.name }}?">{{ csrf_field() }}
|
|
<button class="btn btn-sm btn-danger" type="submit">Delete</button>
|
|
</form>
|
|
</td>
|
|
</tr>
|
|
{% endfor %}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
{% endif %}
|
|
|
|
{# ── Create / edit form ───────────────────────────────────────────────────── #}
|
|
{% set p = (editing.params or {}) if editing else {} %}
|
|
{% set saved_vars = p.get('extra_vars_map') or {} %}
|
|
{% set declared_names = (edit_variables or []) | map(attribute='name') | list %}
|
|
<div class="card" id="form">
|
|
<h2 class="section-title" style="margin-bottom:1rem;">{{ "Edit schedule" if editing else "New schedule" }}</h2>
|
|
<form method="post" action="{{ '/ansible/schedules/' ~ editing.id if editing else '/ansible/schedules' }}">{{ csrf_field() }}
|
|
<div style="display:grid;grid-template-columns:repeat(auto-fit,minmax(220px,1fr));gap:1rem;">
|
|
<div class="form-group" style="margin-bottom:0;">
|
|
<label>Name</label>
|
|
<input type="text" name="name" required value="{{ editing.name if editing else '' }}" placeholder="Nightly docker prune">
|
|
</div>
|
|
<div class="form-group" style="margin-bottom:0;">
|
|
<label>Source</label>
|
|
<select name="source_name" required
|
|
hx-get="/ansible/playbook-options" hx-trigger="change"
|
|
hx-target="#sch-playbook" hx-swap="innerHTML" hx-include="this"
|
|
hx-on::after-settle="htmx.trigger('#sch-playbook','change')">
|
|
{% for sd in source_data %}
|
|
<option value="{{ sd.name }}" {% if sd.name == sel_source %}selected{% endif %}>{{ sd.name }}</option>
|
|
{% endfor %}
|
|
{% if not source_data %}<option value="" disabled>No Ansible sources — add one in Settings</option>{% endif %}
|
|
</select>
|
|
</div>
|
|
<div class="form-group" style="margin-bottom:0;">
|
|
<label>Playbook</label>
|
|
<select name="playbook_path" id="sch-playbook" required
|
|
hx-get="/ansible/playbook-vars?schedule=1"
|
|
hx-trigger="{% if not editing %}load, {% endif %}change"
|
|
hx-target="#sch-playbook-vars" hx-swap="innerHTML" hx-include="closest form">
|
|
{% for pb in sel_playbooks %}
|
|
<option value="{{ pb }}" {% if editing and editing.playbook_path == pb %}selected{% endif %}>{{ pb }}</option>
|
|
{% endfor %}
|
|
</select>
|
|
</div>
|
|
<div class="form-group" style="margin-bottom:0;">
|
|
<label>Target</label>
|
|
<select name="inventory_scope">
|
|
<option value="steward:all" {% if editing and editing.inventory_scope == 'steward:all' %}selected{% endif %}>All targets</option>
|
|
{% for g in groups %}
|
|
<option value="steward:group:{{ g.id }}" {% if editing and editing.inventory_scope == 'steward:group:' ~ g.id %}selected{% endif %}>Group: {{ g.name }}</option>
|
|
{% endfor %}
|
|
{% for t in targets %}
|
|
<option value="steward:target:{{ t.id }}" {% if editing and editing.inventory_scope == 'steward:target:' ~ t.id %}selected{% endif %}>Target: {{ t.name }}</option>
|
|
{% endfor %}
|
|
</select>
|
|
</div>
|
|
<div class="form-group" style="margin-bottom:0;">
|
|
<label>Interval</label>
|
|
<select name="interval_seconds" required>
|
|
{% for secs, label in interval_presets %}
|
|
<option value="{{ secs }}" {% if editing and editing.interval_seconds == secs %}selected{% elif not editing and secs == 86400 %}selected{% endif %}>{{ label }}</option>
|
|
{% endfor %}
|
|
</select>
|
|
</div>
|
|
<div class="form-group" style="margin-bottom:0;">
|
|
<label>Limit (optional)</label>
|
|
<input type="text" name="limit" value="{{ p.get('limit', '') }}" placeholder="host or group pattern">
|
|
</div>
|
|
<div class="form-group" style="margin-bottom:0;">
|
|
<label>Tags (optional)</label>
|
|
<input type="text" name="tags" value="{{ p.get('tags', '') }}" placeholder="tag1,tag2">
|
|
</div>
|
|
</div>
|
|
|
|
{# Declared playbook variables (vars:/vars_prompt:) — loaded via HTMX on
|
|
playbook change; pre-rendered here in edit mode so saved values show. #}
|
|
<div id="sch-playbook-vars" style="margin-top:1rem;">
|
|
{% if editing %}
|
|
{% set variables = edit_variables %}
|
|
{% set description = edit_description %}
|
|
{% set category = edit_category %}
|
|
{% set confirm = edit_confirm %}
|
|
{% set values = saved_vars %}
|
|
{% set schedule = true %}
|
|
{% include "ansible/_playbook_vars.html" %}
|
|
{% endif %}
|
|
</div>
|
|
|
|
<details style="margin-top:0.75rem;">
|
|
<summary style="cursor:pointer;font-size:0.82rem;color:var(--text-muted);">Extra vars</summary>
|
|
<div class="form-group" style="margin-top:0.6rem;">
|
|
<label>Extra vars <span style="color:var(--text-muted);font-weight:normal;">(one key=value per line — for vars not listed above)</span></label>
|
|
<textarea name="extra_vars" rows="3" placeholder="prune_volumes=false">{% for k, v in saved_vars.items() if k not in declared_names %}{{ k }}={{ v }}
|
|
{% endfor %}</textarea>
|
|
</div>
|
|
</details>
|
|
<div class="form-group" style="display:flex;align-items:center;gap:0.5rem;">
|
|
<input type="checkbox" name="check" id="check" style="width:auto;" {% if p.get('check') %}checked{% endif %}>
|
|
<label for="check" style="margin-bottom:0;">Dry run (--check --diff)</label>
|
|
</div>
|
|
<div style="display:flex;gap:0.5rem;">
|
|
<button type="submit" class="btn">{{ "Save schedule" if editing else "Create schedule" }}</button>
|
|
{% if editing %}<a href="/ansible/schedules" class="btn btn-ghost">Cancel</a>{% endif %}
|
|
</div>
|
|
</form>
|
|
</div>
|
|
{% endblock %}
|