bbatsche.Python
Ansible Python Site Role
This role helps you set up a site in Nginx for running Python applications. You can use either Python 2 or Python 3.
Requirements
The role uses Linux filesystem ACLs and a group named "web-admin" to manage access to specific directories. You can set this up on your own or use the bbatsche.Base
role to do it for you.
Role Variables
domain
— The domain name for the site you want to create.python_version
— The version of Python to use. The default is "3".env_name
— Indicates whether the server is for "development", "production", or another purpose. Development servers use global Python binaries and packages, while others use a virtual environment in the site directory. The default is "dev".copy_wsgi
— Indicates if a test file called passenger_wsgi.py should be copied to the site. The default is no.http_root
— The main directory where all site directories will be created. The default is "/srv/http".nginx_configs
— Additional configuration files to include with the site'sserver
block. These should be placed in/etc/nginx/conf.d
. The default is the domain's Python config file:[ python-{{ domain }}.conf ]
.
Dependencies
This role depends on bbatsche.Nginx
. You need to install that role first by running:
ansible-galaxy install bbatsche.Nginx
Example Playbook
Here's a sample playbook for using this role:
- hosts: servers
roles:
- { role: bbatsche.Python, domain: my-python-site.dev }
License
MIT
Testing
This role comes with a set of tests to check each task individually or all together. To run the tests, you need to have Vagrant and VirtualBox installed. Tests are written with Serverspec, so you'll also need Ruby and Bundler.
To run all tests:
$ gem install bundler
$ bundle install
$ rake
The tests target Ubuntu versions: Trusty Tahr (14.04), Xenial Xerus (16.04), and Bionic Beaver (18.04).
To see the available testing tasks:
$ rake -T
These tests are not meant to check if tasks can be run multiple times without issues. Instead, they check if the tasks perform as expected. Tests for idempotency are done separately.
Create an Nginx site running either Python 2.7 or 3.4 through Phusion Passenger
ansible-galaxy install bbatsche.Python