2016-05-12 08:30:26 -04:00
|
|
|
|
Ansible nginx-supervisor
|
2015-01-16 19:45:04 -05:00
|
|
|
|
==============================
|
2014-12-22 18:03:40 -05:00
|
|
|
|
|
2016-05-12 08:30:26 -04:00
|
|
|
|
A base Ansible role that setups and manages a webapp via supervisor, and served up on a NGINX web server. The goal of
|
|
|
|
|
this role is to extract the common elements of deploying a webapp into this infrastructure, in a simple and sane manner.
|
|
|
|
|
Additionally the role provides sane defaults for logging and folder structure setup.
|
|
|
|
|
|
|
|
|
|
**This role is under development and is unstable.**
|
2014-12-22 18:03:40 -05:00
|
|
|
|
|
|
|
|
|
Requirements
|
|
|
|
|
------------
|
|
|
|
|
|
2015-01-16 19:45:04 -05:00
|
|
|
|
- aptitude or python-apt (required by apt tasks)
|
|
|
|
|
|
2016-05-16 18:12:09 -04:00
|
|
|
|
This role is designed to work against a modern Ubuntu system. (Tested on Ubuntu 14.04 and 16.04) It should
|
2015-01-16 19:45:04 -05:00
|
|
|
|
theoretically work on older versions of Ubuntu or Debian based systems.
|
2014-12-22 18:03:40 -05:00
|
|
|
|
|
2015-02-17 18:51:52 -05:00
|
|
|
|
Example Playbook
|
|
|
|
|
----------------
|
|
|
|
|
|
|
|
|
|
The simplest way to include the role in your playbook is to copy the below configuration. Remember to modify the
|
2016-05-12 08:46:45 -04:00
|
|
|
|
app_name, app_nginx_hostname and app_service_command parameters especially.
|
2015-02-17 18:51:52 -05:00
|
|
|
|
|
|
|
|
|
- hosts: servers
|
|
|
|
|
sudo: yes
|
|
|
|
|
roles:
|
2016-05-12 08:46:45 -04:00
|
|
|
|
- { role: nginx-supervisor,
|
2016-05-14 10:56:30 -04:00
|
|
|
|
nsbase_app_name: app,
|
|
|
|
|
nsbase_app_nginx_hostname: app.domain.net,
|
|
|
|
|
nsbase_app_service_command: app_executable --port 9000 }
|
2015-02-17 18:51:52 -05:00
|
|
|
|
|
|
|
|
|
The role itself is very configurable. For exaple, if you prefer the location of the web application to refer to the
|
2016-05-14 10:56:30 -04:00
|
|
|
|
domain name rather than the default root path, then simply override the nsbase_app_root_path variable with something
|
|
|
|
|
like:
|
2015-02-17 18:51:52 -05:00
|
|
|
|
|
2016-05-14 10:56:30 -04:00
|
|
|
|
nsbase_app_rooth_path: "{{ nsbase_web_root_path }}/{{ nsbase_app_nginx_hostname }}"
|
2015-02-17 18:51:52 -05:00
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
2014-12-22 18:03:40 -05:00
|
|
|
|
Role Variables
|
|
|
|
|
--------------
|
|
|
|
|
|
2016-05-14 10:56:30 -04:00
|
|
|
|
There are a few crucial variables that you need to configure for your app. They are broken up into sections and
|
|
|
|
|
described below:
|
|
|
|
|
|
|
|
|
|
Note that all the variables have a prefix `nsbase_` to avoid naming conflicts with other roles.
|
2015-01-19 23:22:58 -05:00
|
|
|
|
|
2015-01-21 09:05:19 -05:00
|
|
|
|
### App Settings
|
2015-01-19 23:22:58 -05:00
|
|
|
|
|
2016-05-14 10:56:30 -04:00
|
|
|
|
- nsbase_app_name:
|
|
|
|
|
- The name of app to manage via this role.
|
2015-01-21 09:05:19 -05:00
|
|
|
|
- Used as a prefix through out the role.
|
2016-05-14 10:56:30 -04:00
|
|
|
|
- nsbase_app_root_path:
|
2015-01-21 09:05:19 -05:00
|
|
|
|
- The path to the root folder of the app.
|
2016-05-14 10:56:30 -04:00
|
|
|
|
- Default: nsbase_web_root_path/nsbase_app_name_webapp
|
2015-01-19 23:22:58 -05:00
|
|
|
|
|
2015-01-21 09:05:19 -05:00
|
|
|
|
### NGINX
|
2015-01-19 23:22:58 -05:00
|
|
|
|
|
2016-05-14 10:56:30 -04:00
|
|
|
|
- nsbase_app_nginx_hostname:
|
2015-01-21 09:05:19 -05:00
|
|
|
|
- The DNS hostname that the application serves.
|
|
|
|
|
- Default: localhost
|
2016-05-14 10:56:30 -04:00
|
|
|
|
- nsbase_app_nginx_app_static:
|
2015-01-21 09:05:19 -05:00
|
|
|
|
- The path to the static elements of the site (templates, CSS, images, etc.)
|
2016-05-14 10:56:30 -04:00
|
|
|
|
- Default: nsbase_app_root_path/nsbase_app_name/static/
|
2015-01-19 23:22:58 -05:00
|
|
|
|
|
2016-05-12 08:46:45 -04:00
|
|
|
|
### App Specific
|
2015-01-21 09:05:19 -05:00
|
|
|
|
|
2016-05-14 10:56:30 -04:00
|
|
|
|
- nsbase_app_service_command:
|
2016-05-12 08:46:45 -04:00
|
|
|
|
- The full command to execute to run the application
|
2016-05-14 10:56:30 -04:00
|
|
|
|
- nsbase_app_service_stop_signal:
|
2016-05-12 08:46:45 -04:00
|
|
|
|
- The signal used to gracefully stop the application.
|
|
|
|
|
- Default: QUIT (as in SIGQUIT)
|
2015-07-21 07:35:26 -04:00
|
|
|
|
|
|
|
|
|
### General Web
|
2015-01-21 09:05:19 -05:00
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
2016-05-14 10:56:30 -04:00
|
|
|
|
- nsbase_web_root_path:
|
2015-01-21 09:05:19 -05:00
|
|
|
|
- The root of the entire web app structure include configuration and logging.
|
|
|
|
|
- Default: /srv/www
|
2016-05-14 10:56:30 -04:00
|
|
|
|
- nsbase_web_server_group:
|
2015-01-21 09:05:19 -05:00
|
|
|
|
- The user group responsible for starting, stopping and managing the web and app servers on the target machine.
|
|
|
|
|
- Default: www-data
|
2016-05-14 10:56:30 -04:00
|
|
|
|
- nsbase_app_service_name:
|
|
|
|
|
- The name of the service setup for the app according to supervisor.
|
|
|
|
|
- Default: nsbase_app_name
|
2015-01-19 23:22:58 -05:00
|
|
|
|
|
2015-02-17 18:51:52 -05:00
|
|
|
|
Default File Structure
|
|
|
|
|
----------------------
|
|
|
|
|
|
|
|
|
|
By default the role will organize files in the following directory structure:
|
|
|
|
|
|
|
|
|
|
/srv/www
|
|
|
|
|
├── config
|
|
|
|
|
│ ├── nginx -> /etc/nginx
|
2016-05-12 08:30:26 -04:00
|
|
|
|
│ └── supervisor -> /etc/supervisor
|
2015-02-17 18:51:52 -05:00
|
|
|
|
├── logs
|
|
|
|
|
│ ├── nginx -> /var/log/nginx
|
2016-05-12 08:30:26 -04:00
|
|
|
|
│ └── supervisor -> /var/log/supervisor
|
|
|
|
|
└── app_webapp
|
|
|
|
|
└── app
|
2015-02-17 18:51:52 -05:00
|
|
|
|
|
|
|
|
|
Internal Variables
|
|
|
|
|
------------------
|
2015-01-19 23:22:58 -05:00
|
|
|
|
|
|
|
|
|
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:
|
|
|
|
|
|
2016-05-14 10:56:30 -04:00
|
|
|
|
- nsbase_web_user:
|
2015-01-21 09:05:19 -05:00
|
|
|
|
- The non-root user who is allowed to control web + app servers on the target machine.
|
|
|
|
|
- Default: current user
|
2016-05-14 10:56:30 -04:00
|
|
|
|
- nsbase_nginx_app_conf:
|
2015-01-21 09:05:19 -05:00
|
|
|
|
- The filename of the NGINX configuration for the app.
|
2016-05-14 10:56:30 -04:00
|
|
|
|
- Default: nsbase_app_name_nginx.conf
|
|
|
|
|
- nsbase_supervisor_app_config:
|
2015-01-21 09:05:19 -05:00
|
|
|
|
- The filename of the supervisor configuration for the app.
|
2016-05-14 10:56:30 -04:00
|
|
|
|
- Default: nsbase_app_name_supervisor.conf
|
2014-12-22 18:03:40 -05:00
|
|
|
|
|
|
|
|
|
License
|
|
|
|
|
-------
|
|
|
|
|
|
2015-01-16 19:45:04 -05:00
|
|
|
|
BSD
|
2014-12-22 18:03:40 -05:00
|
|
|
|
|
|
|
|
|
Author Information
|
|
|
|
|
------------------
|
|
|
|
|
|
2015-01-16 19:45:04 -05:00
|
|
|
|
Dorian Pula
|
2015-01-21 09:05:19 -05:00
|
|
|
|
|
|
|
|
|
- twitter: @dorianpula
|
2015-01-19 23:22:58 -05:00
|
|
|
|
- email: dorian.pula at amber-penguin.software.ca
|
|
|
|
|
- www: http://amber-penguin-software.ca
|
2015-01-16 19:45:04 -05:00
|
|
|
|
|
2015-02-17 18:51:52 -05:00
|
|
|
|
This role is a spin-off of the technology developed for the [Rookeries project] (http://rookeries.org/)
|
2015-01-22 08:22:26 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Repositories
|
|
|
|
|
------------
|
|
|
|
|
|
2016-05-12 08:30:26 -04:00
|
|
|
|
- Main: https://bitbucket.org/dorianpula/ansible-nginx-supervisor
|
2015-01-22 08:22:26 -05:00
|
|
|
|
- All development and issues are worked on this repo.
|