Skip to content

Implement Day-2 Operations: Ansible Playbook Execution from UI

Overview

Implement Day-2 operations functionality allowing users to execute predefined Ansible playbooks against their environments directly from the UI. This enables operational tasks like system updates, security patches, and configuration changes.

Implementation Details

  • Backend Endpoint: POST /api/v1/environments/{id}/run-playbook
  • Request Body: {'playbook': 'update_packages.yml'}
  • Celery Task: run_ansible_playbook(environment_id, playbook_name)
    • Fetch container IPs for the environment
    • Generate dynamic Ansible inventory
    • Execute ansible-playbook via subprocess
  • Frontend: Environment detail page section to list available playbooks with trigger buttons

Subtasks

1. Design Playbook Catalog Structure

Define playbook metadata schema and directory structure in orchestration/ansible/day2/

2. Design and Implement Backend API Endpoint

Create POST /api/v1/environments/{id}/run-playbook endpoint with Pydantic models for request/response validation

3. Create Celery Task for Ansible Playbook Execution

Implement run_ansible_playbook(environment_id, playbook_name) task with proper error handling

  • Depends on: Subtask #2

4. Implement Dynamic Inventory Generation

Build dynamic inventory generator that fetches container IPs and generates Ansible inventory files

  • Depends on: Subtask #3

5. Integrate Ansible Playbook Execution via Subprocess

Integrate subprocess calls to execute ansible-playbook with proper output capture and error handling

  • Depends on: Subtasks #3, #4

6. Develop Frontend UI for Listing and Triggering Playbooks

Add UI section to environment detail page with playbook list and trigger buttons

7. Create Sample Ansible Playbook for Validation

Create update_packages.yml playbook for testing and validation purposes

8. Implement Logging and Status Feedback

Add comprehensive logging and real-time status feedback for playbook execution

  • Depends on: Subtasks #2, #3, #6

Test Strategy

  1. Create a simple update_packages.yml playbook
  2. On the detail page of a running environment, trigger the playbook run
  3. SSH into a container and verify package versions or check apt logs
  4. Monitor Celery worker logs for ansible-playbook command output
  5. Verify error handling and status reporting

Related

  • Taskmaster: Tag master, Task #13
  • Dependencies: Task #9 (Environment Detail Page)
Edited by Jacob Bowen
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information