Here is the complete README.md fully written in English, structured professionally for your GitHub repository:
This repository contains an Ansible playbook and a custom role for the automated, idempotent deployment of a Django-based Todo application on target servers running Ubuntu 24.04 LTS.
- Full Automation: Installs required system packages (
Python 3.12,python3-venv,git), configures the environment, and starts the application with a single command. - Virtualenv Isolation: Deploys the application and its dependencies within an isolated Python virtual environment (
venv) to comply with Ubuntu 24.04 PEP 668 policies. - Automated Database Migrations: Runs Django database migrations natively during the deployment phase before the service restarts, ensuring data consistency.
- Optimized Handlers: Executes systemd
daemon-reloadand service restarts strictly at the end of the playbook, triggering only if actual changes were made to the source code or service configuration. - Systemd Orchestration: Configures the application as a persistent system service with auto-restart policies on failure.
.
├── inventory.yaml # Inventory file specifying managed hosts and SSH access
├── playbook.yaml # Main playbook that executes the deployment role
└── roles/
└── todoapp/ # Custom deployment role for the application
├── defaults/
│ └── main.yaml # Default role variables (paths, repo URL)
├── handlers/
│ └── main.yaml # Handlers for systemd daemon-reload and service restarts
├── tasks/
│ └── main.yaml # Core deployment workflow and step-by-step tasks
└── templates/
└── todoapp_service.j2 # Jinja2 template for the systemd service file
- Control Node (Your machine): Ansible 2.15+ installed.
- Managed Node (Target server): A clean instance of Ubuntu 24.04 LTS with SSH access and
sudoprivileges configured.
Open roles/todoapp/defaults/main.yaml and modify the default variables if your paths or repository URLs differ:
todoapp_path: /app
todoapp_git_url: https://github.com/Killingrace/Todoapp_Ansible.git
todoapp_venv_name: venv
Edit the inventory.yaml file to include your target server's IP address, SSH user, and private key path:
all:
hosts:
todo_server:
ansible_host: 192.168.0.1 # Replace with your server's IP
ansible_user: azureuser # Replace with your SSH user (e.g., ubuntu, root)
ansible_ssh_private_key_file: ~/.ssh/id_ed25519
Before running the playbook, verify the connection to your managed host and check the inventory structure:
# Test connectivity with the ping module
ansible all -m ping -i inventory.yaml
# Verify inventory hierarchy
ansible-inventory -i inventory.yaml --graph
To execute the deployment, run the following command:
ansible-playbook -i inventory.yaml playbook.yaml
Once the deployment finishes successfully, log in to your target server to verify the status of the application:
# Check the systemd service status
systemctl status todoapp
# Stream application logs in real-time
journalctl -u todoapp -f
The application will be accessible via your browser at: http://<YOUR_SERVER_IP>:8080