Turn configurations into templates with variables.

Add multiple variables for all the necessary templated values.
Make the role reusable beyond working with rookeries.
This commit is contained in:
Dorian 2015-01-13 22:45:07 -05:00
parent 862d73268a
commit 771c6bac2d
12 changed files with 75 additions and 69 deletions

View File

@ -1,18 +0,0 @@
server {
server_name localhost;
access_log /srv/www/logs/nginx/rookeries-access.log;
error_log /srv/www/logs/nginx/rookeries-error.log info;
location /static/ {
alias /srv/www/rookeries_webapp/rookeries/static/;
}
location / {
try_files $uri @yourapplication;
}
location @yourapplication {
include uwsgi_params;
uwsgi_pass 127.0.0.1:8001;
}
}

View File

@ -1,9 +0,0 @@
; UWSGI for Rookeries
[program:rookeries_uwsgi]
user=www-data
command=/srv/www/virtualenvs/uwsgi/bin/uwsgi --ini /srv/www/config/uwsgi/rookeries-uwsgi.ini
stopsignal=TERM
stdout_logfile = /srv/www/logs/supervisor/rookeries-application.log
stdout_logfile_backups = 5
stderr_logfile = /srv/www/logs/supervisor/rookeries-error.log
stderr_logfile_backups = 5

View File

@ -1,8 +0,0 @@
[uwsgi]
socket = :8001
master = true
processes = 8
chdir = /srv/www/rookeries_webapp
virtualenv = /srv/www/virtualenvs/rookeries
module = rookeries:make_rookeries_app()

View File

@ -3,17 +3,17 @@
apt: pkg=nginx-full state=present apt: pkg=nginx-full state=present
sudo: yes sudo: yes
# TODO Look at using templated configuration
- name: configure nginx - name: configure nginx
copy: src=nginx/{{ app_nginx_conf }} dest=/etc/nginx/sites-available template: src=nginx/app_uwsgi_nginx.conf dest=/etc/nginx/sites-available/{{ nginx_app_conf }}
- name: enable the copied over nginx configuration
file: state=link
src=/etc/nginx/sites-available/{{ app_nginx_conf }}
path=/etc/nginx/sites-enabled/{{ app_nginx_conf }}
sudo: yes sudo: yes
- name: disable the default page configuration - name: link to enable nginx configuration
file: state=link
src=/etc/nginx/sites-available/{{ nginx_app_conf }}
path=/etc/nginx/sites-enabled/{{ nginx_app_conf }}
sudo: yes
- name: disable default configuration
file: state=absent path=/etc/nginx/sites-enabled/default file: state=absent path=/etc/nginx/sites-enabled/default
sudo: yes sudo: yes
@ -21,7 +21,7 @@
service: name=nginx state=restarted service: name=nginx state=restarted
sudo: yes sudo: yes
- name: set permissions on nginx config + log directories - name: set nginx directories permissions
file: path={{ item }} state=directory file: path={{ item }} state=directory
group={{ web_server_group }} mode=0755 group={{ web_server_group }} mode=0755
with_items: with_items:
@ -31,7 +31,7 @@
- /etc/nginx/sites-enabled - /etc/nginx/sites-enabled
sudo: yes sudo: yes
- name: set permissions on nginx logs - name: set nginx logs permissions
file: path=/var/log/nginx/{{ item }} state=file file: path=/var/log/nginx/{{ item }} state=file
owner={{ web_server_group }} group={{ web_server_group }} mode=0644 owner={{ web_server_group }} group={{ web_server_group }} mode=0644
with_items: with_items:

View File

@ -1,12 +1,12 @@
--- ---
- name: install python dev dependencies - name: install python dev
sudo: yes sudo: yes
apt: pkg={{ item }} state=present apt: pkg={{ item }} state=present
with_items: with_items:
- python-dev - python-dev
- python-setuptools - python-setuptools
- name: bootstrap pip using setuptools - name: install pip
sudo: yes sudo: yes
easy_install: name=pip easy_install: name=pip

View File

@ -19,7 +19,6 @@
chown: root:{{ web_server_group }} chown: root:{{ web_server_group }}
sudo: yes sudo: yes
- name: upload rookeries supervisor configuration to web server home - name: upload supervisor configuration to web server home
copy: src=supervisor/{{ item }} dest=/etc/supervisor/conf.d template: src=supervisor/app_supervisor.conf dest=/etc/supervisor/conf.d/{{ supervisor_app_config }}
with_items: supervisor_configs
sudo: yes sudo: yes

View File

@ -3,8 +3,8 @@
pip: name=uwsgi virtualenv={{ uwsgi_venv }} version=2.0 pip: name=uwsgi virtualenv={{ uwsgi_venv }} version=2.0
sudo: yes sudo: yes
- name: upload app's uwsgi configuration - name: configure app on uwsgi server
copy: src=uwsgi/{{ uwsgi_ini }} dest={{ uwsgi_config }} template: src=uwsgi/app_uwsgi.ini dest={{ uwsgi_config }}/{{ uwsgi_app_ini }}
sudo: yes sudo: yes
- name: restart uwsgi server - name: restart uwsgi server

View File

@ -1,10 +1,11 @@
--- ---
- name: setup webapp deployment folder with the correct permissions - name: setup webapp deployment folder with the correct permissions
file: path={{ web_app_home }} state=directory owner={{ web_server_group }} group=www-data mode=0774 file: path={{ web_root_path }} state=directory
owner={{ web_server_group }} group={{ web_server_group }} mode=0774
sudo: yes sudo: yes
- name: setup webapp deployment configuration + log folders with the correct permissions - name: setup webapp deployment configuration + log folders with the correct permissions
file: path={{ web_app_home }}/{{ item }} state=directory file: path={{ web_root_path }}/{{ item }} state=directory
owner={{ web_server_group }} group={{ web_server_group }} mode=0774 owner={{ web_server_group }} group={{ web_server_group }} mode=0774
with_items: with_items:
- config - config
@ -15,7 +16,7 @@
- name: link remote folders with webapp home folder - name: link remote folders with webapp home folder
file: state=link file: state=link
path={{ web_app_home }}/{{ item.value }} path={{ web_root_path }}/{{ item.value }}
src={{ item.key }} src={{ item.key }}
owner={{ web_server_group }} group={{ web_server_group }} mode=0774 owner={{ web_server_group }} group={{ web_server_group }} mode=0774
with_dict: with_dict:
@ -26,5 +27,5 @@
sudo: yes sudo: yes
- name: add user to webserver group - name: add user to webserver group
user: name={{ user }} append=yes groups={{ web_server_group }} user: name={{ web_user }} append=yes groups={{ web_server_group }}
sudo: yes sudo: yes

View File

@ -0,0 +1,18 @@
server {
server_name {{ nginx_hostname }};
access_log {{ web_root_path }}/logs/nginx/{{ app_name }}-access.log;
error_log {{ web_root_path }}/logs/nginx/{{ app_name }}-error.log info;
location /static/ {
alias {{ nginx_app_static }};
}
location / {
try_files $uri @yourapplication;
}
location @yourapplication {
include uwsgi_params;
uwsgi_pass 127.0.0.1:{{ uwsgi_port }};
}
}

View File

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

View File

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

View File

@ -1,23 +1,29 @@
--- ---
# vars file for ansible-nginx-uwsgi-supervisor # vars file for ansible-nginx-uwsgi-supervisor
# TODO Make more configurable and flexible # Web root paths + app name + home
app_name: rookeries
# Web app home + group web_root_path: /srv/www
web_app_home: /srv/www
web_server_group: www-data web_server_group: www-data
user: "{{ ansible_env.SUDO_USER }}" web_user: "{{ ansible_env.SUDO_USER }}"
app_home: "{{ web_root_path }}/{{ app_name }}_webapp"
# Virtualenvs
virtualenv_root: "{{ web_root_path }}/virtualenvs"
uwsgi_venv: "{{ virtualenv_root }}/uwsgi"
app_venv: "{{ virtualenv_root }}/{{ app_name }}"
# NGINX # NGINX
app_nginx_conf: rookeries-uwsgi_nginx.conf nginx_hostname: localhost
nginx_app_static: "{{ app_home }}/{{ app_name }}/static/"
nginx_app_conf: "{{ app_name }}_uwsgi_nginx.conf"
# Supervisor # Supervisor
# TODO Allow for multiple supervisord configurations supervisor_app_config: "{{ app_name }}_supervisor.conf"
supervisor_configs:
# - mailsink_supervisor.conf
- rookeries_supervisor.conf
# UWSGI # UWSGI
uwsgi_venv: "{{ web_app_home }}/virtualenvs/uwsgi" uwsgi_config: "{{ web_root_path }}/config/uwsgi"
uwsgi_config: "{{ web_app_home }}/config/uwsgi" uwsgi_app_ini: "{{ app_name }}_uwsgi.ini"
uwsgi_ini: rookeries-uwsgi.ini uwsgi_port: 8001
uwsgi_service_name: "{{ app_name }}_uwsgi"
uwsgi_app_executable: rookeries:make_rookeries_app()