feat(hosts): re-provision action on reporting hosts; Ansible off the edit page
- Host agent panel (reporting state) gains a "Re-provision" collapsible (admin + linked target + managed key): bootstrap user/password → provision.yml, which reinstalls the steward account + managed key + agent. This is the missing path after regenerating the managed key — Update alone can't fix a broken key. - Remove the Ansible sections (run-playbook + target link) from the host EDIT page — they were the stale free-text version and the wrong place. They live on the host detail hub (dropdown + discovered variables). Edit page now links to the host page; edit_host route simplified (no ansible fetch). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
+3
-25
@@ -304,38 +304,16 @@ async def create_host():
|
||||
@hosts_bp.get("/<host_id>/edit")
|
||||
@require_role(UserRole.operator)
|
||||
async def edit_host(host_id: str):
|
||||
from steward.models.ansible_inventory import AnsibleTarget
|
||||
from sqlalchemy.orm import selectinload
|
||||
|
||||
# Pure host config (name/address/monitors). Agent, Ansible target linking,
|
||||
# and playbook runs live on the host detail page (the hub), not here.
|
||||
async with current_app.db_sessionmaker() as db:
|
||||
result = await db.execute(select(Host).where(Host.id == host_id))
|
||||
host = result.scalar_one_or_none()
|
||||
if host is None:
|
||||
return "Not found", 404
|
||||
|
||||
linked_result = await db.execute(
|
||||
select(AnsibleTarget)
|
||||
.where(AnsibleTarget.host_id == host_id)
|
||||
.options(selectinload(AnsibleTarget.groups))
|
||||
)
|
||||
linked_target = linked_result.scalar_one_or_none()
|
||||
|
||||
# Only show targets not yet linked to any host (plus the currently linked one)
|
||||
linkable_result = await db.execute(
|
||||
select(AnsibleTarget)
|
||||
.where(AnsibleTarget.host_id.is_(None))
|
||||
.order_by(AnsibleTarget.name)
|
||||
)
|
||||
linkable_targets = linkable_result.scalars().all()
|
||||
|
||||
return await render_template(
|
||||
"hosts/form.html",
|
||||
host=host,
|
||||
probe_types=list(ProbeType),
|
||||
ansible_sources=_ansible_source_names(),
|
||||
linked_target=linked_target,
|
||||
linkable_targets=linkable_targets,
|
||||
)
|
||||
"hosts/form.html", host=host, probe_types=list(ProbeType))
|
||||
|
||||
|
||||
@hosts_bp.post("/<host_id>")
|
||||
|
||||
@@ -51,90 +51,11 @@
|
||||
</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>
|
||||
|
||||
{% if host %}
|
||||
<div class="card" style="margin-top:1.5rem;max-width:560px;margin-left:auto;margin-right:auto;">
|
||||
<h3 class="section-title">Ansible Target</h3>
|
||||
{% if linked_target %}
|
||||
<div style="display:flex;align-items:center;gap:1rem;padding:0.75rem;background:var(--bg-elevated);border-radius:4px;margin-bottom:1rem;">
|
||||
<div style="flex:1;">
|
||||
<strong>{{ linked_target.name }}</strong>
|
||||
<span style="color:var(--text-muted);font-size:0.85rem;margin-left:0.5rem;">{{ linked_target.address }}</span>
|
||||
{% if linked_target.groups %}
|
||||
<div style="margin-top:0.25rem;">
|
||||
{% for grp in linked_target.groups %}
|
||||
<span style="font-size:0.78rem;background:var(--bg);border-radius:3px;padding:0.1em 0.4em;margin-right:0.2rem;color:var(--text-muted);">{{ grp.name }}</span>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
<a href="/ansible/inventory/targets/{{ linked_target.id }}" class="btn btn-ghost btn-sm">Edit Target</a>
|
||||
<form method="post" action="/hosts/{{ host.id }}/ansible-link" style="display:inline;">
|
||||
<input type="hidden" name="action" value="unlink">
|
||||
<button type="submit" class="btn btn-ghost btn-sm">Unlink</button>
|
||||
</form>
|
||||
</div>
|
||||
{% else %}
|
||||
<p style="color:var(--text-muted);font-size:0.9rem;margin-bottom:1rem;">
|
||||
No Ansible target linked. Link an existing target or create one from this host.
|
||||
{% if host %}
|
||||
<p style="color:var(--text-muted);font-size:0.82rem;margin-top:1rem;text-align:center;">
|
||||
Agent, Ansible target, and playbook runs live on the
|
||||
<a href="/hosts/{{ host.id }}">host page</a>.
|
||||
</p>
|
||||
<div style="display:flex;gap:0.75rem;flex-wrap:wrap;align-items:flex-end;">
|
||||
{% if linkable_targets %}
|
||||
<form method="post" action="/hosts/{{ host.id }}/ansible-link" style="display:flex;gap:0.5rem;align-items:center;flex:1;">
|
||||
<input type="hidden" name="action" value="link">
|
||||
<select name="target_id" style="flex:1;">
|
||||
{% for tgt in linkable_targets %}
|
||||
<option value="{{ tgt.id }}">{{ tgt.name }} ({{ tgt.address }})</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<button type="submit" class="btn btn-sm">Link</button>
|
||||
</form>
|
||||
{% endif %}
|
||||
<form method="post" action="/hosts/{{ host.id }}/ansible-link">
|
||||
<input type="hidden" name="action" value="create">
|
||||
<button type="submit" class="btn btn-sm btn-ghost">Create Target from This Host</button>
|
||||
</form>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
Reference in New Issue
Block a user