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-playbookvia 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
Test Strategy
- Create a simple
update_packages.ymlplaybook - On the detail page of a running environment, trigger the playbook run
- SSH into a container and verify package versions or check apt logs
- Monitor Celery worker logs for
ansible-playbookcommand output - Verify error handling and status reporting
Related
-
Taskmaster: Tag
master, Task #13 - Dependencies: Task #9 (Environment Detail Page)