Installing NGINX with a remote `apt` command works once. Doing it again on another server raises more questions: Is NGINX already installed? Is it configured and running? Does a configuration change require a restart? Ansible replaces a growing sequence of manual commands with a repeatable description of how the machine should be set up. section 4.2 section 4.1.5
Ansible is an infrastructure-as-code tool for configuring remote machines. Its YAML files, called playbooks, declare a *desired state*—for example, that a package is present or a service has the right configuration. Ansible connects over SSH, so the machine running it needs access to the target machine through the appropriate SSH keys. section 4.2 section 4.0
A Python application deployment shows how a playbook turns that goal into tasks:
- Update the package cache, then use Ansible’s `apt` task to require Python dependencies, NGINX, and Supervisor with `state: present`. section 4.2.3
- Create a Python virtual environment and application directories; copy the application to the server and install packages from `requirements.txt`. section 4.2.3
- Copy Supervisor and NGINX configuration files. Configuration tasks notify handlers that reload Supervisor or restart NGINX when needed. section 4.2.3
Listing 4.12 Installing Python with Ansible Playbook, part 3
- name: Install dependencies
apt:
pkg:
- python3-pip
- python3-dev
- python3-venv
- rsync
- nginx
- supervisor
state: present
The dependency task names the required packages and declares them `present`, rather than expressing installation as a one-off shell command. section 4.2.3
Listing 4.17 Installing Python with Ansible Playbook, part 8
- name: Configure gunicorn and uvicorn with supervisor
copy:
src: '{{ playbook_dir }}/../../conf/supervisor.conf'
dest: /etc/supervisor/conf.d/roadtok8s-py.conf
notify: reload supervisor
- name: Configure nginx
copy:
src: '{{ playbook_dir }}/../../conf/nginx.conf'
dest: /etc/nginx/sites-available/roadtok8s-py
notify: restart nginx
These copy tasks place the application’s service configurations on the remote machine and notify the relevant service handlers. section 4.2.3
Run the deployment from GitHub Actions
After defining the playbook, a GitHub Actions workflow can run `ansible-playbook deploy-python.yaml` from its Ansible directory. The workflow starts the deployment; Ansible handles the remote machine’s configuration. This is more robust than extending the workflow with many separate SSH and file-copy commands. section 4.2.3 section 4.1.5

