Make variables more consistent across roles.
This commit is contained in:
parent
893cd03e74
commit
063f5ffc96
61
README.md
61
README.md
|
@ -1,4 +1,4 @@
|
||||||
Ansible nginx-uwsgi-supervisor
|
Ansible uwsgi-nginx-supervisor
|
||||||
==============================
|
==============================
|
||||||
|
|
||||||
An Ansible role to setup and manage a UWSGI app via supervisor, and served up on a NGINX web server. The goal of this
|
An Ansible role to setup and manage a UWSGI app via supervisor, and served up on a NGINX web server. The goal of this
|
||||||
|
@ -10,6 +10,7 @@ Requirements
|
||||||
|
|
||||||
- aptitude or python-apt (required by apt tasks)
|
- aptitude or python-apt (required by apt tasks)
|
||||||
- python > 2.5 (required by ini_file tasks)
|
- python > 2.5 (required by ini_file tasks)
|
||||||
|
- Ansible >= 2.0
|
||||||
|
|
||||||
This role is designed to work against a modern Ubuntu system. (Tested on Ubuntu 14.04 and 16.04) It should
|
This role is designed to work against a modern Ubuntu system. (Tested on Ubuntu 14.04 and 16.04) It should
|
||||||
theoretically work on older versions of Ubuntu or Debian based systems.
|
theoretically work on older versions of Ubuntu or Debian based systems.
|
||||||
|
@ -20,21 +21,21 @@ Example Playbook
|
||||||
----------------
|
----------------
|
||||||
|
|
||||||
The simplest way to include the role in your playbook is to copy the below configuration. Remember to modify the
|
The simplest way to include the role in your playbook is to copy the below configuration. Remember to modify the
|
||||||
app_name, app_nginx_hostname and app_uwsgi_executable parameters especially.
|
uwsgi_app_name, uwsgi_app_nginx_hostname and uwsgi_app_executable parameters especially.
|
||||||
|
|
||||||
- hosts: servers
|
- hosts: servers
|
||||||
sudo: yes
|
sudo: yes
|
||||||
roles:
|
roles:
|
||||||
- { role: nginx-uwsgi-supervisor,
|
- { role: nginx-uwsgi-supervisor,
|
||||||
app_name: app,
|
uwsgi_app_name: app,
|
||||||
app_nginx_hostname: app.domain.net,
|
uwsgi_app_nginx_hostname: app.domain.net,
|
||||||
app_uwsgi_port: 8080,
|
uwsgi_app_port: 8080,
|
||||||
app_uwsgi_executable: "app.build:make_wsgi_app()" }
|
uwsgi_app_executable: "app.build:make_wsgi_app()" }
|
||||||
|
|
||||||
The role itself is very configurable. For exaple, if you prefer the location of the web application to refer to the
|
The role itself is very configurable. For exaple, if you prefer the location of the web application to refer to the
|
||||||
domain name rather than the default root path, then simply override the app_root_path variable with something like:
|
domain name rather than the default root path, then simply override the app_root_path variable with something like:
|
||||||
|
|
||||||
app_rooth_path: "{{ web_root_path }}/{{ app_nginx_hostname }}"
|
uwsgi_app_rooth_path: "{{ uwsgi_web_root_path }}/{{ uwsgi_app_nginx_hostname }}"
|
||||||
|
|
||||||
A comprehensive example can be found in the [Ansible rookeries role]
|
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.
|
(https://bitbucket.org/dorianpula/ansible-rookeries) that uses this role as a base to deploy a Flask-based webapp.
|
||||||
|
@ -47,31 +48,31 @@ into sections and described below:
|
||||||
|
|
||||||
### App Settings
|
### App Settings
|
||||||
|
|
||||||
- app_name:
|
- uwsgi_app_name:
|
||||||
- The name of WSGI app to manage via this role.
|
- The name of WSGI app to manage via this role.
|
||||||
- Used as a prefix through out the role.
|
- Used as a prefix through out the role.
|
||||||
- app_root_path:
|
- uwsgi_app_root_path:
|
||||||
- The path to the root folder of the app.
|
- The path to the root folder of the app.
|
||||||
- Default: web_root_path/app_name_webapp
|
- Default: uwsgi_web_root_path/uwsgi_app_name_webapp
|
||||||
|
|
||||||
### NGINX
|
### NGINX
|
||||||
|
|
||||||
- app_nginx_hostname:
|
- uwsgi_app_nginx_hostname:
|
||||||
- The DNS hostname that the application serves.
|
- The DNS hostname that the application serves.
|
||||||
- Default: localhost
|
- Default: localhost
|
||||||
- app_nginx_app_static:
|
- uwsgi_app_static_path:
|
||||||
- The path to the static elements of the site (templates, CSS, images, etc.)
|
- The path to the static elements of the site (templates, CSS, images, etc.)
|
||||||
- Default: app_root_path/app_name/static/
|
- Default: uwsgi_app_root_path/uwsgi_app_name/static/
|
||||||
|
|
||||||
### UWSGI
|
### UWSGI
|
||||||
|
|
||||||
- app_uwsgi_port:
|
- uwsgi_app_port:
|
||||||
- The port number that the WSGI runs on and accepts requests forwarded from NGINX.
|
- The port number that the WSGI runs on and accepts requests forwarded from NGINX.
|
||||||
- Default: 8001
|
- Default: 8001
|
||||||
- app_uwsgi_executable:
|
- uwsgi_app_executable:
|
||||||
- The method executed by UWSGI to create a WSGI running app. Usually a WSGI factory method or module in the app.
|
- 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()
|
- Default: app:make_wsgi_app()
|
||||||
- app_uwsgi_envs:
|
- uwsgi_app_envs:
|
||||||
- (Optional) A dictionary of environment variables to pass into an app.
|
- (Optional) A dictionary of environment variables to pass into an app.
|
||||||
- Default: empty dictionary
|
- Default: empty dictionary
|
||||||
|
|
||||||
|
@ -79,22 +80,22 @@ into sections and described below:
|
||||||
|
|
||||||
On occasion it is necessary to change the setup of the virtual environments on a system.
|
On occasion it is necessary to change the setup of the virtual environments on a system.
|
||||||
|
|
||||||
- virtualenv_root_path:
|
- uwsgi_virtualenv_root_path:
|
||||||
- Path to where the virtual environments are installed
|
- Path to where the virtual environments are installed
|
||||||
- Default: web_root_path/virtualenvs
|
- Default: uwsgi_web_root_path/virtualenvs
|
||||||
- app_venv:
|
- uwsgi_app_venv:
|
||||||
- Path to the application's virtualenv.
|
- Path to the application's virtualenv.
|
||||||
- Default: virtualenv_root_path/app_name
|
- Default: uwsgi_virtualenv_root_path/uwsgi_app_name
|
||||||
|
|
||||||
### General Web
|
### General Web
|
||||||
|
|
||||||
These variables are not as crucial to configure. They do give good defaults for configuring the system in a consistent,
|
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.
|
POSIX/LSB-friendly and user-friendly manner. See the section on Default File Structure for more details.
|
||||||
|
|
||||||
- web_root_path:
|
- uwsgi_web_root_path:
|
||||||
- The root of the entire web app structure include configuration and logging.
|
- The root of the entire web app structure include configuration and logging.
|
||||||
- Default: /srv/www
|
- Default: /srv/www
|
||||||
- web_server_group:
|
- uwsgi_web_server_group:
|
||||||
- The user group responsible for starting, stopping and managing the web and app servers on the target machine.
|
- The user group responsible for starting, stopping and managing the web and app servers on the target machine.
|
||||||
- Default: www-data
|
- Default: www-data
|
||||||
|
|
||||||
|
@ -112,7 +113,7 @@ By default the role will organize files in the following directory structure:
|
||||||
│ ├── nginx -> /var/log/nginx
|
│ ├── nginx -> /var/log/nginx
|
||||||
│ ├── supervisor -> /var/log/supervisor
|
│ ├── supervisor -> /var/log/supervisor
|
||||||
│ └── uwsgi
|
│ └── uwsgi
|
||||||
├── app_webapp
|
├── uwsgi_app_webapp
|
||||||
│ ├── requirements.txt
|
│ ├── requirements.txt
|
||||||
│ └── app
|
│ └── app
|
||||||
└── virtualenvs
|
└── virtualenvs
|
||||||
|
@ -125,19 +126,19 @@ 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:
|
||||||
|
|
||||||
- virtualenv_root_path:
|
- uwsgi_virtualenv_root_path:
|
||||||
- The common root directory of Python virtual environments associated with running the
|
- The common root directory of Python virtual environments associated with running the
|
||||||
UWSGI app + server.
|
UWSGI app + server.
|
||||||
- Default: /srv/www/virtualenvs/
|
- Default: /srv/www/virtualenvs/
|
||||||
- uwsgi_venv:
|
- uwsgi_venv:
|
||||||
- The virtual environment where UWSGI is installed.
|
- The virtual environment where UWSGI is installed.
|
||||||
- Default: virtualenv_root/uwsgi
|
- Default: uwsgi_virtualenv_root/uwsgi
|
||||||
- app_venv:
|
- uwsgi_app_venv:
|
||||||
- The virtual environment where the dependencies of the WSGI app is installed.
|
- The virtual environment where the dependencies of the WSGI app is installed.
|
||||||
- Default: virtualenv_root/app_name
|
- Default: uwsgi_virtualenv_root/uwsgi_app_name
|
||||||
- nginx_app_conf:
|
- uwsgi_app_nginx_conf:
|
||||||
- The filename of the NGINX configuration for the app.
|
- The filename of the NGINX configuration for the app.
|
||||||
- Default: app_name_uwsgi_nginx.conf
|
- Default: uwsgi_app_name_nginx.conf
|
||||||
- uwsgi_config_path:
|
- uwsgi_config_path:
|
||||||
- The path to the UWSGI configurations.
|
- The path to the UWSGI configurations.
|
||||||
- Default: /srv/www/config/uwsgi
|
- Default: /srv/www/config/uwsgi
|
||||||
|
@ -168,7 +169,7 @@ This role is a spin-off of the technology developed for the [Rookeries project]
|
||||||
Repositories
|
Repositories
|
||||||
------------
|
------------
|
||||||
|
|
||||||
- Main: https://bitbucket.org/dorianpula/ansible-nginx-uwsgi-supervisor
|
- Main: https://bitbucket.org/dorianpula/ansible-uwsgi-nginx-supervisor
|
||||||
- All development and issues are worked on this repo.
|
- All development and issues are worked on this repo.
|
||||||
- Clone: https://github.com/dorianpula/ansible-nginx-uwsgi-supervisor
|
- Clone: https://github.com/dorianpula/ansible-nginx-uwsgi-supervisor
|
||||||
- A clone to work with Ansible Galaxy and Github
|
- A clone to work with Ansible Galaxy and Github
|
||||||
|
|
|
@ -2,21 +2,21 @@
|
||||||
# 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
|
||||||
web_root_path: /srv/www
|
uwsgi_web_root_path: /srv/www
|
||||||
web_server_group: www-data
|
uwsgi_web_server_group: www-data
|
||||||
|
|
||||||
app_name: app
|
uwsgi_app_name: app
|
||||||
app_root_path: "{{ web_root_path }}/{{ app_name }}_webapp"
|
uwsgi_app_root_path: "{{ uwsgi_web_root_path }}/{{ uwsgi_app_name }}_webapp"
|
||||||
|
|
||||||
# NGINX
|
# NGINX
|
||||||
app_nginx_hostname: localhost
|
uwsgi_app_hostname: localhost
|
||||||
app_nginx_static_path: "{{ app_root_path }}/{{ app_name }}/static/"
|
uwsgi_app_static_path: "{{ uwsgi_app_root_path }}/{{ uwsgi_app_name }}/static/"
|
||||||
|
|
||||||
# UWSGI
|
# UWSGI
|
||||||
app_uwsgi_port: 8000
|
uwsgi_app_port: 8000
|
||||||
app_uwsgi_executable: "app:make_wsgi_app()"
|
uwsgi_app_executable: "app:make_wsgi_app()"
|
||||||
app_uwsgi_envs: {}
|
uwsgi_app_envs: {}
|
||||||
|
|
||||||
# Virtualenvs
|
# Virtualenvs
|
||||||
virtualenv_root_path: "{{ web_root_path }}/virtualenvs"
|
uwsgi_virtualenv_root_path: "{{ uwsgi_web_root_path }}/virtualenvs"
|
||||||
app_venv: "{{ virtualenv_root_path }}/{{ app_name }}"
|
uwsgi_app_venv: "{{ uwsgi_virtualenv_root_path }}/{{ uwsgi_app_name }}"
|
||||||
|
|
|
@ -16,10 +16,11 @@ galaxy_info:
|
||||||
dependencies:
|
dependencies:
|
||||||
# - role: "git+https://bitbucket.org/dorianpula/ansible-nginx-supervisor,,nginx-supervisor"
|
# - role: "git+https://bitbucket.org/dorianpula/ansible-nginx-supervisor,,nginx-supervisor"
|
||||||
- role: "nginx-supervisor"
|
- role: "nginx-supervisor"
|
||||||
nsbase_app_name: "{{ app_name }}"
|
nsbase_app_name: "{{ uwsgi_app_name }}"
|
||||||
nsbase_app_root_path: "{{ app_root_path }}"
|
nsbase_app_root_path: "{{ uwsgi_app_root_path }}"
|
||||||
nsbase_app_nginx_hostname: "{{ app_nginx_hostname }}"
|
nsbase_app_hostname: "{{ uwsgi_app_hostname }}"
|
||||||
nsbase_app_service_name: "{{ uwsgi_app_service_name }}"
|
nsbase_app_service_name: "{{ uwsgi_app_service_name }}"
|
||||||
nsbase_app_service_command: "{{ uwsgi_supervisor_app_command }}"
|
nsbase_app_service_command: "{{ uwsgi_app_supervisor_command }}"
|
||||||
nsbase_app_service_stop_signal: QUIT
|
nsbase_app_service_stop_signal: QUIT
|
||||||
nsbase_nginx_app_config: "{{ uwsgi_nginx_app_config }}"
|
nsbase_app_nginx_config: "{{ uwsgi_app_nginx_config }}"
|
||||||
|
nsbase_app_nginx_static_path: "{{ uwsgi_app_static_path }}"
|
||||||
|
|
|
@ -10,11 +10,11 @@
|
||||||
|
|
||||||
- name: configure nginx app with uwsgi specific block.
|
- name: configure nginx app with uwsgi specific block.
|
||||||
blockinfile:
|
blockinfile:
|
||||||
dest: /etc/nginx/sites-available/{{ nginx_app_config }}
|
dest: /etc/nginx/sites-available/{{ uwsgi_app_nginx_config }}
|
||||||
insertafter: "# Include your setup to connect to the webapp setup here."
|
insertafter: "# Include your setup to connect to the webapp setup here."
|
||||||
marker: "# -- {mark} UWSGI App config for {{ app_name }} --"
|
marker: "# -- {mark} UWSGI App config for {{ uwsgi_app_name }} --"
|
||||||
block: |
|
block: |
|
||||||
include uwsgi_params;
|
include uwsgi_params;
|
||||||
uwsgi_pass 127.0.0.1:{{ app_uwsgi_port }};
|
uwsgi_pass 127.0.0.1:{{ uwsgi_app_port }};
|
||||||
sudo: yes
|
sudo: yes
|
||||||
notify: restart nginx
|
notify: restart nginx
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
[uwsgi]
|
[uwsgi]
|
||||||
socket = :{{ app_uwsgi_port }}
|
socket = :{{ uwsgi_app_port }}
|
||||||
master = true
|
master = true
|
||||||
processes = 8
|
processes = 8
|
||||||
|
|
||||||
chdir = {{ app_root_path }}
|
chdir = {{ uwsgi_app_root_path }}
|
||||||
virtualenv = {{ app_venv }}
|
virtualenv = {{ uwsgi_app_venv }}
|
||||||
module = {{ app_uwsgi_executable }}
|
module = {{ uwsgi_app_executable }}
|
||||||
|
|
||||||
{% for env_var, env_value in app_uwsgi_envs.items() %}
|
{% for env_var, env_value in uwsgi_app_envs.items() %}
|
||||||
env = {{ env_var | upper }}={{ env_value }}
|
env = {{ env_var | upper }}={{ env_value }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
|
@ -2,14 +2,13 @@
|
||||||
# vars file for ansible-nginx-uwsgi-supervisor
|
# vars file for ansible-nginx-uwsgi-supervisor
|
||||||
|
|
||||||
# NGINX
|
# NGINX
|
||||||
nginx_app_config: "{{ app_name }}_uwsgi_nginx.conf"
|
uwsgi_app_nginx_config: "{{ uwsgi_app_name }}_uwsgi_nginx.conf"
|
||||||
|
|
||||||
# UWSGI
|
# UWSGI
|
||||||
uwsgi_venv: "{{ virtualenv_root_path }}/uwsgi"
|
uwsgi_venv: "{{ uwsgi_virtualenv_root_path }}/uwsgi"
|
||||||
uwsgi_config_path: "{{ web_root_path }}/config/uwsgi"
|
uwsgi_config_path: "{{ uwsgi_web_root_path }}/config/uwsgi"
|
||||||
uwsgi_app_ini: "{{ app_name }}_uwsgi.ini"
|
uwsgi_app_ini: "{{ uwsgi_app_name }}_uwsgi.ini"
|
||||||
uwsgi_app_service_name: "{{ app_name }}_uwsgi"
|
uwsgi_app_service_name: "{{ uwsgi_app_name }}_uwsgi"
|
||||||
|
|
||||||
# TODO: Document extracted variables
|
# TODO: Document extracted variables
|
||||||
uwsgi_supervisor_app_command: "{{ uwsgi_venv }}/bin/uwsgi --ini {{ uwsgi_config_path }}/{{ uwsgi_app_ini }}"
|
uwsgi_app_supervisor_command: "{{ uwsgi_venv }}/bin/uwsgi --ini {{ uwsgi_config_path }}/{{ uwsgi_app_ini }}"
|
||||||
uwsgi_nginx_app_config: "{{ app_name }}_uwsgi_nginx.conf"
|
|
||||||
|
|
Loading…
Reference in New Issue