feat(ansible): per-variable fields in the playbook run form
When you click Run, Steward now parses the playbook and renders a field for each declared variable instead of a blank extra-vars textarea. The form loads on demand via HTMX (/ansible/run-form/<source>/<playbook>). - sources.discover_playbook_variables: parse vars: defaults + vars_prompt: (vars_prompt wins on name collision; non-scalar vars skipped; role/include vars not traversed). Flags secret-looking names + vars_prompt private. - Run-time values flow through a JSON extra-vars file (-e @file), which is space/quote-safe — fixes a latent shlex-split bug in the old -e key=value textarea path. executor.build_extra_vars_file (pure) + start_run merge. - Secret-flagged fields are masked AND routed through an unpersisted secret_vars channel (runner.trigger_run → start_run), so passwords entered at run time never land in the DB / run history. - Defaults shown as placeholders (not prefilled): an untouched field falls through to the inventory/play default instead of overriding it. - routes: run_form HTMX endpoint; _parse_run_params now returns (params, secret_vars, err) and reads var__/secret__ fields. Schedules drop secret vars (can't prompt unattended). - templates: ansible/_run_form.html fragment; browse.html rewired to HTMX, static JS run-form removed. Advanced section keeps limit/tags/check + a free-form extra-vars escape hatch. - tests: test_playbook_variables.py (discovery + extra-vars file). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
{# Run form for a single playbook — loaded via HTMX from /ansible/run-form/… #}
|
||||
<div style="background:var(--bg-elevated);border-radius:6px;padding:1rem;border:1px solid var(--border-mid);">
|
||||
<div style="display:flex;align-items:center;justify-content:space-between;margin-bottom:0.75rem;">
|
||||
<h4 class="section-title" style="margin-bottom:0;">Run <span style="font-family:ui-monospace,monospace;font-weight:normal;">{{ playbook_path }}</span></h4>
|
||||
<a href="#" onclick="this.closest('div[id^=run-form-]').innerHTML='';return false;"
|
||||
class="btn btn-ghost btn-sm">Cancel</a>
|
||||
</div>
|
||||
<form hx-post="/ansible/runs" hx-target="next .run-result" hx-swap="innerHTML">
|
||||
<input type="hidden" name="source_name" value="{{ source_name }}">
|
||||
<input type="hidden" name="playbook_path" value="{{ playbook_path }}">
|
||||
|
||||
<div class="form-group">
|
||||
<label>Run against</label>
|
||||
<select name="inventory_scope">
|
||||
{% if targets %}
|
||||
<option value="steward:all">All targets ({{ targets | length }})</option>
|
||||
{% if groups %}
|
||||
<optgroup label="Group">
|
||||
{% for grp in groups %}<option value="steward:group:{{ grp.id }}">Group: {{ grp.name }}</option>{% endfor %}
|
||||
</optgroup>
|
||||
{% endif %}
|
||||
<optgroup label="Single target">
|
||||
{% for tgt in targets %}<option value="steward:target:{{ tgt.id }}">{{ tgt.name }}</option>{% endfor %}
|
||||
</optgroup>
|
||||
{% endif %}
|
||||
{% if inventories %}
|
||||
<optgroup label="Repo inventory file">
|
||||
{% for inv in inventories %}<option value="repo:{{ source_name }}:{{ inv }}">{{ source_name }}/{{ inv }}</option>{% endfor %}
|
||||
</optgroup>
|
||||
{% endif %}
|
||||
{% if not targets and not inventories %}
|
||||
<option value="" disabled>No targets or inventory files — add targets at /ansible/inventory/targets</option>
|
||||
{% endif %}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
{% if variables %}
|
||||
<div style="margin:0.5rem 0 0.25rem;font-size:0.82rem;color:var(--text-muted);font-weight:600;">
|
||||
Playbook variables
|
||||
</div>
|
||||
<p style="color:var(--text-dim);font-size:0.76rem;margin:0 0 0.6rem;">
|
||||
Leave a field blank to use the playbook/inventory default. Secret fields are
|
||||
never stored.
|
||||
</p>
|
||||
{% for v in variables %}
|
||||
<div class="form-group">
|
||||
<label>
|
||||
{{ v.prompt or v.name }}
|
||||
<span style="color:var(--text-muted);font-weight:normal;font-size:0.76rem;">
|
||||
({{ v.name }}{% if v.required %}, required{% endif %}{% if v.secret %}, secret{% endif %})
|
||||
</span>
|
||||
</label>
|
||||
{% if v.secret %}<input type="hidden" name="secret__{{ v.name }}" value="1">{% endif %}
|
||||
<input type="{{ 'password' if v.secret else 'text' }}"
|
||||
name="var__{{ v.name }}"
|
||||
{% if v.required %}required{% endif %}
|
||||
{% if v.secret %}autocomplete="new-password"{% endif %}
|
||||
placeholder="{% if v.secret %}(hidden){% elif v.default not in (None, '') %}default: {{ v.default }}{% else %}no default{% endif %}"
|
||||
style="width:100%;font-family:ui-monospace,monospace;font-size:0.85rem;">
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
<p style="color:var(--text-dim);font-size:0.8rem;margin:0.25rem 0 0.6rem;">
|
||||
No declared variables found in this playbook.
|
||||
</p>
|
||||
{% endif %}
|
||||
|
||||
<details style="margin:0.25rem 0 0.75rem;">
|
||||
<summary style="cursor:pointer;font-size:0.82rem;color:var(--text-muted);">Advanced</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)</span></label>
|
||||
<textarea name="extra_vars" rows="2" placeholder="custom_var=value"
|
||||
style="width:100%;font-family:ui-monospace,monospace;font-size:0.85rem;"></textarea>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Limit to host(s) <span style="color:var(--text-muted);font-weight:normal;">(--limit)</span></label>
|
||||
<input type="text" name="limit" placeholder="web01,db*">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Tags <span style="color:var(--text-muted);font-weight:normal;">(--tags)</span></label>
|
||||
<input type="text" name="tags" placeholder="deploy,config">
|
||||
</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) — preview changes without applying
|
||||
</label>
|
||||
</div>
|
||||
</details>
|
||||
|
||||
<div style="display:flex;gap:0.75rem;align-items:center;">
|
||||
<button type="submit" class="btn">Execute</button>
|
||||
</div>
|
||||
</form>
|
||||
<div class="run-result" style="margin-top:1rem;"></div>
|
||||
</div>
|
||||
@@ -76,88 +76,17 @@
|
||||
{% if sd.editable and session.user_role == 'admin' %}
|
||||
<a href="/ansible/playbooks/edit/{{ sd.source.name }}/{{ pb }}" class="btn btn-sm btn-ghost" style="margin-right:0.5rem;">Edit</a>
|
||||
{% endif %}
|
||||
<a href="#run-form-{{ sd.source.name }}"
|
||||
onclick="document.getElementById('run-form-{{ sd.source.name }}').style.display='block';
|
||||
document.getElementById('run-playbook-{{ sd.source.name }}').value='{{ pb }}';
|
||||
document.getElementById('run-playbook-display-{{ sd.source.name }}').value='{{ pb }}';
|
||||
return false;"
|
||||
class="btn btn-sm btn-ghost">Run</a>
|
||||
<a hx-get="/ansible/run-form/{{ sd.source.name }}/{{ pb }}"
|
||||
hx-target="#run-form-{{ sd.source.name }}" hx-swap="innerHTML"
|
||||
style="cursor:pointer;" class="btn btn-sm btn-ghost">Run</a>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
{# Run trigger form for this source #}
|
||||
<div id="run-form-{{ sd.source.name }}" style="display:none;background:var(--bg-elevated);border-radius:6px;padding:1rem;border:1px solid var(--border-mid);">
|
||||
<h4 class="section-title" style="margin-bottom:0.75rem;">Trigger Run</h4>
|
||||
<form hx-post="/ansible/runs" hx-target="#run-result-{{ sd.source.name }}" hx-swap="innerHTML">
|
||||
<input type="hidden" name="source_name" value="{{ sd.source.name }}">
|
||||
<input type="hidden" id="run-playbook-{{ sd.source.name }}" name="playbook_path" value="">
|
||||
<div class="form-group">
|
||||
<label>Playbook</label>
|
||||
<input type="text" id="run-playbook-display-{{ sd.source.name }}"
|
||||
readonly style="color:var(--text-muted);" value="">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Run Against</label>
|
||||
<select name="inventory_scope">
|
||||
{% if targets %}
|
||||
<optgroup label="All Targets">
|
||||
<option value="steward:all">All targets ({{ targets | length }})</option>
|
||||
</optgroup>
|
||||
{% if groups %}
|
||||
<optgroup label="Group">
|
||||
{% for grp in groups %}
|
||||
<option value="steward:group:{{ grp.id }}">Group: {{ grp.name }}</option>
|
||||
{% endfor %}
|
||||
</optgroup>
|
||||
{% endif %}
|
||||
<optgroup label="Single Target">
|
||||
{% for tgt in targets %}
|
||||
<option value="steward:target:{{ tgt.id }}">{{ tgt.name }}</option>
|
||||
{% endfor %}
|
||||
</optgroup>
|
||||
{% endif %}
|
||||
{% if sd.inventories %}
|
||||
<optgroup label="Repo Inventory File">
|
||||
{% for inv in sd.inventories %}
|
||||
<option value="repo:{{ sd.source.name }}:{{ inv }}">{{ sd.source.name }}/{{ inv }}</option>
|
||||
{% endfor %}
|
||||
</optgroup>
|
||||
{% endif %}
|
||||
{% if not targets and not sd.inventories %}
|
||||
<option value="" disabled>No targets or inventory files — add targets at /ansible/inventory/targets</option>
|
||||
{% endif %}
|
||||
</select>
|
||||
</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" placeholder="version=1.2.3 restart=true"
|
||||
style="width:100%;font-family:ui-monospace,monospace;font-size:0.85rem;"></textarea>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Limit to host(s) <span style="color:var(--text-muted);font-weight:normal;">(optional, --limit)</span></label>
|
||||
<input type="text" name="limit" placeholder="web01,db*">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Tags <span style="color:var(--text-muted);font-weight:normal;">(optional, --tags)</span></label>
|
||||
<input type="text" name="tags" placeholder="deploy,config">
|
||||
</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) — preview changes without applying
|
||||
</label>
|
||||
</div>
|
||||
<div style="display:flex;gap:0.75rem;align-items:center;">
|
||||
<button type="submit" class="btn">Execute</button>
|
||||
<a href="#" onclick="document.getElementById('run-form-{{ sd.source.name }}').style.display='none';return false;"
|
||||
class="btn btn-ghost btn-sm">Cancel</a>
|
||||
</div>
|
||||
</form>
|
||||
<div id="run-result-{{ sd.source.name }}" style="margin-top:1rem;"></div>
|
||||
</div>
|
||||
{# Run form (loaded on demand via HTMX from /ansible/run-form/<source>/<pb>) #}
|
||||
<div id="run-form-{{ sd.source.name }}"></div>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
||||
Reference in New Issue
Block a user