Migrate variables into a separate module.

Turn included playbooks into pure task modules.
This commit is contained in:
Dorian 2015-01-07 18:23:43 -05:00
parent dcabd1a549
commit 8892de863c
6 changed files with 110 additions and 102 deletions

View File

@ -5,5 +5,3 @@
- include: supervisor.yaml - include: supervisor.yaml
- include: web_data_folders.yaml - include: web_data_folders.yaml
- include: uwsgi.yaml - include: uwsgi.yaml
# TODO Add in globally defined values for webapp and virtualenv folders

View File

@ -1,28 +1,26 @@
--- ---
- sudo: yes - name: install nginx webserver
vars:
rookeries_nginx_conf: rookeries-uwsgi_nginx.conf
web_server_group: www-data
tasks:
- name: install nginx webserver
apt: pkg=nginx-full state=present apt: pkg=nginx-full state=present
sudo: yes
- name: configure nginx - name: configure nginx
copy: src=../config/nginx/{{ rookeries_nginx_conf }} dest=/etc/nginx/sites-available copy: src=../config/nginx/{{ rookeries_nginx_conf }} dest=/etc/nginx/sites-available
- name: enable the rookeries nginx configuration - name: enable the rookeries nginx configuration
file: state=link file: state=link
src=/etc/nginx/sites-available/{{ rookeries_nginx_conf }} src=/etc/nginx/sites-available/{{ rookeries_nginx_conf }}
path=/etc/nginx/sites-enabled/{{ rookeries_nginx_conf }} path=/etc/nginx/sites-enabled/{{ rookeries_nginx_conf }}
sudo: yes
- name: disable the default page configuration - name: disable the default page configuration
file: state=absent path=/etc/nginx/sites-enabled/default file: state=absent path=/etc/nginx/sites-enabled/default
sudo: yes
- name: restart nginx - name: restart nginx
service: name=nginx state=restarted service: name=nginx state=restarted
sudo: yes
- name: set permissions on nginx config + log directories - name: set permissions on nginx config + log directories
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:
@ -30,10 +28,12 @@
- /etc/nginx - /etc/nginx
- /etc/nginx/sites-available - /etc/nginx/sites-available
- /etc/nginx/sites-enabled - /etc/nginx/sites-enabled
sudo: yes
- name: set permissions on nginx logs - name: set permissions on nginx logs
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:
- access.log - access.log
- error.log - error.log
sudo: yes

View File

@ -1,29 +1,25 @@
--- ---
- sudo: yes - name: install supervisord
vars:
web_server_group: www-data
supervisor_configs:
- mailsink_supervisor.conf
- rookeries_supervisor.conf
tasks:
- name: install supervisord
apt: name=supervisor state=present apt: name=supervisor state=present
sudo: yes
- name: set permissions on supervisor config and log directories - name: set permissions on supervisor config and log directories
file: path={{ item }} group={{ web_server_group }} state=directory mode=0755 file: path={{ item }} group={{ web_server_group }} state=directory mode=0755
with_items: with_items:
- /etc/supervisor - /etc/supervisor
- /etc/supervisor/conf.d - /etc/supervisor/conf.d
- /var/log/supervisor - /var/log/supervisor
sudo: yes
- name: modify supervisor configuration - name: modify supervisor configuration
ini_file: dest=/etc/supervisor/supervisord.conf section=unix_http_server ini_file: dest=/etc/supervisor/supervisord.conf section=unix_http_server
option={{ item.key }} value={{ item.value }} option={{ item.key }} value={{ item.value }}
with_dict: with_dict:
chmod: "0770" chmod: "0770"
chown: root:www-data chown: root:{{ web_server_group }}
sudo: yes
- name: upload rookeries supervisor configuration to web server home - name: upload rookeries supervisor configuration to web server home
copy: src=../config/supervisor/{{ item }} dest=/etc/supervisor/conf.d copy: src=../config/supervisor/{{ item }} dest=/etc/supervisor/conf.d
with_items: supervisor_configs with_items: supervisor_configs
sudo: yes

View File

@ -1,17 +1,12 @@
--- ---
- vars: - name: install uwsgi server
web_server_home: /srv/www
web_server_group: www-data
uwsgi_venv: "{{ web_server_home }}/virtualenvs/uwsgi"
uwsgi_config: "{{ web_server_home }}/config/uwsgi"
rookeries_uwsgi_ini: rookeries-uwsgi.ini
tasks:
- name: install uwsgi server
pip: name=uwsgi virtualenv={{ uwsgi_venv }} version=2.0 pip: name=uwsgi virtualenv={{ uwsgi_venv }} version=2.0
sudo: yes
- name: upload rookeries configuration - name: upload rookeries configuration
copy: src=../config/uwsgi/{{ rookeries_uwsgi_ini }} dest={{ uwsgi_config }} copy: src=../config/uwsgi/{{ rookeries_uwsgi_ini }} dest={{ uwsgi_config }}
sudo: yes
- name: restart uwsgi server - name: restart uwsgi server
supervisorctl: name=uwsgi state=restarted config=/etc/supervisor/supervisor.conf supervisorctl: name=uwsgi state=restarted config=/etc/supervisor/supervisor.conf
sudo: yes

View File

@ -1,15 +1,9 @@
--- ---
- sudo: yes - name: setup webapp deployment folder with the correct permissions
vars:
user: "{{ ansible_env.SUDO_USER }}"
web_app_home: /srv/www
web_server_group: www-data
tasks:
- 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_app_home }} state=directory owner={{ web_server_group }} group=www-data mode=0774
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_app_home }}/{{ 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:
@ -17,8 +11,9 @@
- config/uwsgi - config/uwsgi
- logs - logs
- virtualenvs - virtualenvs
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: state=link file: state=link
path={{ web_app_home }}/{{ item.value }} path={{ web_app_home }}/{{ item.value }}
src={{ item.key }} src={{ item.key }}
@ -28,6 +23,8 @@
/etc/supervisor: config/supervisor /etc/supervisor: config/supervisor
/var/log/nginx: logs/nginx /var/log/nginx: logs/nginx
/var/log/supervisor: logs/supervisor /var/log/supervisor: logs/supervisor
sudo: yes
- name: add user to www-data - name: add user to www-data
user: name={{ user }} append=yes groups={{ web_server_group }} user: name={{ user }} append=yes groups={{ web_server_group }}
sudo: yes

View File

@ -1,2 +1,24 @@
--- ---
# vars file for ansible-nginx-uwsgi-supervisor # vars file for ansible-nginx-uwsgi-supervisor
# TODO Make more configurable and flexible
# NGINX
rookeries_nginx_conf: rookeries-uwsgi_nginx.conf
web_server_group: www-data
# Supervisor
# TODO Allow for multiple supervisord configurations
supervisor_configs:
# - mailsink_supervisor.conf
- rookeries_supervisor.conf
web_server_home: /srv/www
# UWSGI
uwsgi_venv: "{{ web_server_home }}/virtualenvs/uwsgi"
uwsgi_config: "{{ web_server_home }}/config/uwsgi"
rookeries_uwsgi_ini: rookeries-uwsgi.ini
# Web folders
user: "{{ ansible_env.SUDO_USER }}"
web_app_home: /srv/www