Add remaining documentation to the README.

Also update role with more consistent variable names.
This commit is contained in:
Dorian 2015-01-21 09:05:19 -05:00
parent e505c10368
commit 1af4792a61
9 changed files with 99 additions and 55 deletions

103
README.md
View File

@ -17,42 +17,81 @@ theoretically work on older versions of Ubuntu or Debian based systems.
Role Variables Role Variables
-------------- --------------
### Default Variables There are a few crucial variables that you need to configure for your particular WSGI powered app. They are broken up
into sections and described below:
TODO - Explanation ### App Settings
# Web root paths + app name + home - app_name:
app_name: app - The name of WSGI app to manage via this role.
web_root_path: /srv/www - Used as a prefix through out the role.
web_server_group: www-data - app_root_path:
app_home: "{{ web_root_path }}/{{ app_name }}_webapp" - The path to the root folder of the app.
- Default: {{ web_root_path }}/{{ app_name }}_webapp"
# NGINX ### NGINX
nginx_hostname: localhost
nginx_app_static: "{{ app_home }}/{{ app_name }}/static/"
# UWSGI - app_nginx_hostname:
uwsgi_port: 8001 - The DNS hostname that the application serves.
uwsgi_app_executable: "app:make_wsgi_app()" - Default: localhost
- app_nginx_app_static:
- The path to the static elements of the site (templates, CSS, images, etc.)
- Default: app_root_path/app_name/static/
### UWSGI
- app_uwsgi_port:
- The port number that the WSGI runs on and accepts requests forwarded from NGINX.
- Default: 8001
- app_uwsgi_executable:
- The method executed by UWSGI to create a WSGI running app. Usually a WSGI factory method or module in the app.
- Default: app:make_wsgi_app()
### General Web:
These variables are not as crucial to configure. They do give good defaults for configuring the system in a consistent,
POSIX/LSB-friendly and user-friendly manner. See the section on Default File Structure for more details.
- web_root_path:
- The root of the entire web app structure include configuration and logging.
- Default: /srv/www
- web_server_group:
- The user group responsible for starting, stopping and managing the web and app servers on the target machine.
- Default: www-data
### Main (Internal) Variables ### Main (Internal) Variables
The following variables are part of the internals of the role. However if you really want to, you can tweak them to The following variables are part of the internals of the role. However if you really want to, you can tweak them to
work with your setup: work with your setup:
- web_user: The non-root user who is allowed to control web + app servers on the target machine. - web_user:
(Default: current user) - The non-root user who is allowed to control web + app servers on the target machine.
- virtualenv_root: The common root directory of Python virtual environments associated with running the UWSGI app + - Default: current user
server. (Default: /srv/www/virtualenvs/) - virtualenv_root_path:
- uwsgi_venv: The virtual environment where UWSGI is installed. (Default: virtualenv_root/uwsgi) - The common root directory of Python virtual environments associated with running the
- app_venv: The virtual environment where the dependencies of the WSGI app is installed. UWSGI app + server.
(Default: virtualenv_root/app_name) - Default: /srv/www/virtualenvs/
- nginx_app_conf: The filename of the NGINX configuration for the app. (Default: app_name_uwsgi_nginx.conf) - uwsgi_venv:
- supervisor_app_config: The filename of the supervisor configuration for the app. (Default: app_name_supervisor.conf) - The virtual environment where UWSGI is installed.
- uwsgi_config: The path to the UWSGI configurations. (Default: /srv/www/config/uwsgi) - Default: virtualenv_root/uwsgi
- uwsgi_app_ini: The filename of the UWSGI INI configuration for the app. (Default: app_name_uwsgi.ini) - app_venv:
- uwsgi_service_name: The name of the UWSGI setup for the app according to supervisor. (Default: app_name_uwsgi) - The virtual environment where the dependencies of the WSGI app is installed.
- Default: virtualenv_root/app_name
- nginx_app_conf:
- The filename of the NGINX configuration for the app.
- Default: app_name_uwsgi_nginx.conf
- supervisor_app_config:
- The filename of the supervisor configuration for the app.
- Default: app_name_supervisor.conf
- uwsgi_config_path:
- The path to the UWSGI configurations.
- Default: /srv/www/config/uwsgi
- uwsgi_app_ini:
- The filename of the UWSGI INI configuration for the app.
- Default: app_name_uwsgi.ini
- uwsgi_service_name:
- The name of the UWSGI setup for the app according to supervisor.
- Default: app_name_uwsgi
Example Playbook Example Playbook
---------------- ----------------
@ -66,9 +105,12 @@ app_name, nginx_hostname and uwsgi_app_executable parameters especially.
roles: roles:
- { role: ansible-nginx-uwsgi-supervisor, - { role: ansible-nginx-uwsgi-supervisor,
app_name: app, app_name: app,
nginx_hostname: app.domain.net, app_nginx_hostname: app.domain.net,
uwsgi_port: 8080, app_uwsgi_port: 8080,
uwsgi_app_executable: "app.build:make_wsgi_app()" } app_uwsgi_executable: "app.build:make_wsgi_app()" }
A comprehensive example can be found in the [ansible-rookeries role]
(https://bitbucket.org/dorianpula/ansible-rookeries) that uses this role as a base to deploy a Flask-based webapp.
Default File Structure Default File Structure
---------------------- ----------------------
@ -100,8 +142,9 @@ Author Information
------------------ ------------------
Dorian Pula Dorian Pula
- twitter: @dorianpula
- email: dorian.pula at amber-penguin.software.ca - email: dorian.pula at amber-penguin.software.ca
- www: http://amber-penguin-software.ca - www: http://amber-penguin-software.ca
This role is a spin-off of the technology developed for the [Rookeries project]: This role is a spin-off of the technology developed for the [Rookeries project] (http://rookeri.es/)
http://rookeries.amber-penguin-software.ca/

View File

@ -2,15 +2,16 @@
# defaults file for ansible-nginx-uwsgi-supervisor # defaults file for ansible-nginx-uwsgi-supervisor
# Web root paths + app name + home # Web root paths + app name + home
app_name: app
web_root_path: /srv/www web_root_path: /srv/www
web_server_group: www-data web_server_group: www-data
app_home: "{{ web_root_path }}/{{ app_name }}_webapp"
app_name: app
app_root_path: "{{ web_root_path }}/{{ app_name }}_webapp"
# NGINX # NGINX
nginx_hostname: localhost app_nginx_hostname: localhost
nginx_app_static: "{{ app_home }}/{{ app_name }}/static/" app_nginx_static_path: "{{ app_root_path }}/{{ app_name }}/static/"
# UWSGI # UWSGI
uwsgi_port: 8000 app_uwsgi_port: 8000
uwsgi_app_executable: "app:make_wsgi_app()" app_uwsgi_executable: "app:make_wsgi_app()"

View File

@ -1,7 +1,7 @@
--- ---
# handlers file for ansible-nginx-uwsgi-supervisor # handlers file for ansible-nginx-uwsgi-supervisor
- name: restart uwsgi app - name: restart uwsgi app
supervisorctl: name={{ uwsgi_service_name }} state=restarted config=/etc/supervisor/supervisor.conf supervisorctl: name={{ uwsgi_app_service_name }} state=restarted config=/etc/supervisor/supervisor.conf
sudo: yes sudo: yes
- name: restart supervisord - name: restart supervisord

View File

@ -4,13 +4,13 @@
sudo: yes sudo: yes
- name: configure nginx - name: configure nginx
template: src=nginx/app_uwsgi_nginx.conf dest=/etc/nginx/sites-available/{{ nginx_app_conf }} template: src=nginx/app_uwsgi_nginx.conf dest=/etc/nginx/sites-available/{{ nginx_app_config }}
sudo: yes sudo: yes
- name: link to enable nginx configuration - name: link to enable nginx configuration
file: state=link file: state=link
src=/etc/nginx/sites-available/{{ nginx_app_conf }} src=/etc/nginx/sites-available/{{ nginx_app_config }}
path=/etc/nginx/sites-enabled/{{ nginx_app_conf }} path=/etc/nginx/sites-enabled/{{ nginx_app_config }}
sudo: yes sudo: yes
- name: disable default configuration - name: disable default configuration

View File

@ -4,5 +4,5 @@
sudo: yes sudo: yes
- name: configure app on uwsgi server - name: configure app on uwsgi server
template: src=uwsgi/app_uwsgi.ini dest={{ uwsgi_config }}/{{ uwsgi_app_ini }} template: src=uwsgi/app_uwsgi.ini dest={{ uwsgi_config_path }}/{{ uwsgi_app_ini }}
sudo: yes sudo: yes

View File

@ -5,7 +5,7 @@ server {
error_log {{ web_root_path }}/logs/nginx/{{ app_name }}-error.log info; error_log {{ web_root_path }}/logs/nginx/{{ app_name }}-error.log info;
location /static/ { location /static/ {
alias {{ nginx_app_static }}; alias {{ app_nginx_static_path }};
} }
location / { location / {

View File

@ -1,7 +1,7 @@
; UWSGI for {{ app_name }} ; UWSGI for {{ app_name }}
[program:{{ uwsgi_service_name }}] [program:{{ uwsgi_app_service_name }}]
user={{ web_server_group }} user={{ web_server_group }}
command={{ uwsgi_venv }}/bin/uwsgi --ini {{ uwsgi_config }}/{{ uwsgi_app_ini }} command={{ uwsgi_venv }}/bin/uwsgi --ini {{ uwsgi_config_path }}/{{ uwsgi_app_ini }}
stopsignal=TERM stopsignal=TERM
stdout_logfile = {{ web_root_path }}/logs/supervisor/{{ app_name }}-application.log stdout_logfile = {{ web_root_path }}/logs/supervisor/{{ app_name }}-application.log
stdout_logfile_backups = 5 stdout_logfile_backups = 5

View File

@ -1,8 +1,8 @@
[uwsgi] [uwsgi]
socket = :{{ uwsgi_port }} socket = :{{ app_uwsgi_port }}
master = true master = true
processes = 8 processes = 8
chdir = {{ app_home }} chdir = {{ app_root_path }}
virtualenv = {{ app_venv }} virtualenv = {{ app_venv }}
module = {{ uwsgi_app_executable }} module = {{ app_uwsgi_executable }}

View File

@ -1,21 +1,21 @@
--- ---
# vars file for ansible-nginx-uwsgi-supervisor # vars file for ansible-nginx-uwsgi-supervisor
# Web root paths + app name + home # User
web_user: "{{ ansible_env.SUDO_USER }}" web_user: "{{ ansible_env.SUDO_USER }}"
# Virtualenvs # Virtualenvs
virtualenv_root: "{{ web_root_path }}/virtualenvs" virtualenv_root_path: "{{ web_root_path }}/virtualenvs"
uwsgi_venv: "{{ virtualenv_root }}/uwsgi" uwsgi_venv: "{{ virtualenv_root_path }}/uwsgi"
app_venv: "{{ virtualenv_root }}/{{ app_name }}" app_venv: "{{ virtualenv_root_path }}/{{ app_name }}"
# NGINX # NGINX
nginx_app_conf: "{{ app_name }}_uwsgi_nginx.conf" nginx_app_config: "{{ app_name }}_uwsgi_nginx.conf"
# Supervisor # Supervisor
supervisor_app_config: "{{ app_name }}_supervisor.conf" supervisor_app_config: "{{ app_name }}_supervisor.conf"
# UWSGI # UWSGI
uwsgi_config: "{{ web_root_path }}/config/uwsgi" uwsgi_config_path: "{{ web_root_path }}/config/uwsgi"
uwsgi_app_ini: "{{ app_name }}_uwsgi.ini" uwsgi_app_ini: "{{ app_name }}_uwsgi.ini"
uwsgi_service_name: "{{ app_name }}_uwsgi" uwsgi_app_service_name: "{{ app_name }}_uwsgi"