From e8a243ef149f960fa06ec93f7740ff0d8ae21e94 Mon Sep 17 00:00:00 2001 From: Dorian Pula Date: Mon, 22 Dec 2014 18:03:40 -0500 Subject: [PATCH] Add basic Ansible role layout for UWSGI, NGINX and supervisor setup. --- README.md | 44 ++++++ config/base/_vimrc | 7 - config/rookeries_webapp_config.cfg | 21 --- config/supervisor/mailsink_supervisor.conf | 8 -- defaults/main.yml | 2 + deployment.yaml | 4 - deployment/email_server.yaml | 13 -- deployment/rookeries_install.yaml | 25 ---- .../nginx/rookeries-uwsgi_nginx.conf | 0 .../supervisor/rookeries_supervisor.conf | 0 {config => files}/uwsgi/rookeries-uwsgi.ini | 0 handlers/main.yml | 2 + meta/main.yml | 128 ++++++++++++++++++ pre_deployment.yaml | 10 -- pre_deployment/base_linux.yaml | 10 -- pre_deployment/mysql_db.yaml | 23 ---- pre_deployment/nodejs.yaml | 19 --- tasks/main.yml | 9 ++ {pre_deployment => tasks}/nginx.yaml | 0 {pre_deployment => tasks}/python.yaml | 0 {pre_deployment => tasks}/supervisor.yaml | 0 {deployment => tasks}/uwsgi.yaml | 0 .../web_data_folders.yaml | 0 vars/main.yml | 2 + 24 files changed, 187 insertions(+), 140 deletions(-) create mode 100644 README.md delete mode 100644 config/base/_vimrc delete mode 100644 config/rookeries_webapp_config.cfg delete mode 100644 config/supervisor/mailsink_supervisor.conf create mode 100644 defaults/main.yml delete mode 100644 deployment.yaml delete mode 100644 deployment/email_server.yaml delete mode 100644 deployment/rookeries_install.yaml rename {config => files}/nginx/rookeries-uwsgi_nginx.conf (100%) rename {config => files}/supervisor/rookeries_supervisor.conf (100%) rename {config => files}/uwsgi/rookeries-uwsgi.ini (100%) create mode 100644 handlers/main.yml create mode 100644 meta/main.yml delete mode 100644 pre_deployment.yaml delete mode 100644 pre_deployment/base_linux.yaml delete mode 100644 pre_deployment/mysql_db.yaml delete mode 100644 pre_deployment/nodejs.yaml create mode 100644 tasks/main.yml rename {pre_deployment => tasks}/nginx.yaml (100%) rename {pre_deployment => tasks}/python.yaml (100%) rename {pre_deployment => tasks}/supervisor.yaml (100%) rename {deployment => tasks}/uwsgi.yaml (100%) rename {pre_deployment => tasks}/web_data_folders.yaml (100%) create mode 100644 vars/main.yml diff --git a/README.md b/README.md new file mode 100644 index 0000000..009839c --- /dev/null +++ b/README.md @@ -0,0 +1,44 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the +role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in +defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables +that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as +well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be +set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for +users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +AGPL v3 + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/config/base/_vimrc b/config/base/_vimrc deleted file mode 100644 index 91470f9..0000000 --- a/config/base/_vimrc +++ /dev/null @@ -1,7 +0,0 @@ -:syntax on -:set number -:set textwidth=125 -:set autoindent -:set shiftwidth=4 -:set nobackup -:set nowritebackup diff --git a/config/rookeries_webapp_config.cfg b/config/rookeries_webapp_config.cfg deleted file mode 100644 index 4646799..0000000 --- a/config/rookeries_webapp_config.cfg +++ /dev/null @@ -1,21 +0,0 @@ -# Basic environmental -ENVIRONMENTAL_NAME = "Vagrant" -TESTING = False -DEBUG = True - -# Password salts + secrets -PASSWORD_SALT = "secret" -SECRET_KEY = "development" -USER_REGISTRATION_INVITE_KEY = None - -# Database -DATABASE_URI = "mysql+mysqlconnector://rookeries:penguin2013flight@localhost:3306/rookeries?charset=utf8" - -# Mail server configuration -MAIL_SERVER = "localhost" -MAIL_PORT = 25 -MAIL_USERNAME = "admin@rookeri.es" -MAIL_PASSWORD = "password" -MAIL_DEFAULT_SENDER = "admin@rookeri.es" -MAIL_USE_TLS = False -MAIL_USE_SSL = False diff --git a/config/supervisor/mailsink_supervisor.conf b/config/supervisor/mailsink_supervisor.conf deleted file mode 100644 index c8add03..0000000 --- a/config/supervisor/mailsink_supervisor.conf +++ /dev/null @@ -1,8 +0,0 @@ -; Mailsink configuration -[program:mailsink] -command=/srv/www/virtualenvs/mail_server/bin/mailsinkd -w 8025 -s 25 -stopsignal=TERM -stdout_logfile = /srv/www/logs/supervisor/mailsink-application.log -stdout_logfile_backups = 5 -stderr_logfile=/srv/www/logs/supervisor/mailsink-error.log -stderr_logfile_backups=5 diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..e913734 --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for ansible-nginx-uwsgi-supervisor diff --git a/deployment.yaml b/deployment.yaml deleted file mode 100644 index 68b5aa0..0000000 --- a/deployment.yaml +++ /dev/null @@ -1,4 +0,0 @@ ---- -- include: deployment/rookeries_install.yaml -- include: deployment/uwsgi.yaml -- include: deployment/email_server.yaml diff --git a/deployment/email_server.yaml b/deployment/email_server.yaml deleted file mode 100644 index ad618e4..0000000 --- a/deployment/email_server.yaml +++ /dev/null @@ -1,13 +0,0 @@ ---- -- hosts: all - sudo: yes - vars: - web_server_home: /srv/www - email_server_venv: "{{ web_server_home }}/virtualenvs/mail_server" - tasks: - - - name: install mailsink test server into target virtualenv - pip: name=mailsink virtualenv={{ email_server_venv }} version=0.0.2 - - - name: restart up the mailsink program - supervisorctl: name=mailsink state=restarted config=/etc/supervisor/supervisor.conf diff --git a/deployment/rookeries_install.yaml b/deployment/rookeries_install.yaml deleted file mode 100644 index c19fea9..0000000 --- a/deployment/rookeries_install.yaml +++ /dev/null @@ -1,25 +0,0 @@ ---- -- hosts: all - sudo: yes - vars: - web_server_home: /srv/www - web_server_group: www-data - rookeries_venv: "{{ web_server_home }}/virtualenvs/rookeries" - rookeries_package: rookeries-0.4.0.tar.bz2 - tasks: - - - name: upload + extract rookeries package to web server home - unarchive: src=../../../{{ rookeries_package }} dest={{ web_server_home }}/ - - - name: install rookeries dependencies - pip: requirements=rookeries_webapp/requirements.txt virtualenv={{ rookeries_venv }} chdir={{ web_server_home }} - - - name: install extra MySQL python connector dependency - pip: name=mysql-connector-python virtualenv={{ rookeries_venv }} version=1.1.6 - extra_args='--allow-external mysql-connector-python --allow-unverified mysql-connector-python' - - - name: fix permissions on extracted web app - file: path={{ web_server_home }}/rookeries_webapp owner={{ web_server_group }} group={{ web_server_group }} - state=directory recurse=yes - - # TODO Step 4 - Setup environment variables on target system related to config. diff --git a/config/nginx/rookeries-uwsgi_nginx.conf b/files/nginx/rookeries-uwsgi_nginx.conf similarity index 100% rename from config/nginx/rookeries-uwsgi_nginx.conf rename to files/nginx/rookeries-uwsgi_nginx.conf diff --git a/config/supervisor/rookeries_supervisor.conf b/files/supervisor/rookeries_supervisor.conf similarity index 100% rename from config/supervisor/rookeries_supervisor.conf rename to files/supervisor/rookeries_supervisor.conf diff --git a/config/uwsgi/rookeries-uwsgi.ini b/files/uwsgi/rookeries-uwsgi.ini similarity index 100% rename from config/uwsgi/rookeries-uwsgi.ini rename to files/uwsgi/rookeries-uwsgi.ini diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100644 index 0000000..32c38c8 --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for ansible-nginx-uwsgi-supervisor diff --git a/meta/main.yml b/meta/main.yml new file mode 100644 index 0000000..7b1f0ef --- /dev/null +++ b/meta/main.yml @@ -0,0 +1,128 @@ +--- +galaxy_info: + author: your name + description: + company: your company (optional) + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + min_ansible_version: 1.2 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + #platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + # - trusty + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + #categories: + #- cloud + #- cloud:ec2 + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + #- system + #- web +dependencies: [] + # List your role dependencies here, one per line. Only + # dependencies available via galaxy should be listed here. + # Be sure to remove the '[]' above if you add dependencies + # to this list. + diff --git a/pre_deployment.yaml b/pre_deployment.yaml deleted file mode 100644 index 60a92cc..0000000 --- a/pre_deployment.yaml +++ /dev/null @@ -1,10 +0,0 @@ ---- -- include: pre_deployment/base_linux.yaml -- include: pre_deployment/python.yaml -- include: pre_deployment/mysql_db.yaml -- include: pre_deployment/nginx.yaml -- include: pre_deployment/supervisor.yaml -- include: pre_deployment/web_data_folders.yaml -- include: pre_deployment/nodejs.yaml - -# TODO Add in globally defined values for webapp and virtualenv folders diff --git a/pre_deployment/base_linux.yaml b/pre_deployment/base_linux.yaml deleted file mode 100644 index ee8dcfd..0000000 --- a/pre_deployment/base_linux.yaml +++ /dev/null @@ -1,10 +0,0 @@ ---- -- hosts: all - sudo: yes - tasks: - - - name: install vim - apt: pkg=vim state=present - - - name: configure vim - copy: src=../config/base/_vimrc dest=/home/vagrant/.vimrc diff --git a/pre_deployment/mysql_db.yaml b/pre_deployment/mysql_db.yaml deleted file mode 100644 index e3e3f43..0000000 --- a/pre_deployment/mysql_db.yaml +++ /dev/null @@ -1,23 +0,0 @@ ---- -- hosts: all - sudo: yes - vars: - databases: - rookeries: - username: rookeries - password: system_admin - tasks: - - - name: setup MySQL server + Python dependencies - apt: pkg={{ item }} state=present - with_items: - - mysql-server - - python-mysqldb - - - name: setup MySQL databases for rookeries. - mysql_db: name={{ item.key }} state=present - with_dict: databases - - - name: add MySQL database users for rookeries. - mysql_user: name={{ item.value.username }} password={{ item.value.password }} priv={{ item.key }}:ALL - with_dict: databases diff --git a/pre_deployment/nodejs.yaml b/pre_deployment/nodejs.yaml deleted file mode 100644 index 3eca965..0000000 --- a/pre_deployment/nodejs.yaml +++ /dev/null @@ -1,19 +0,0 @@ ---- -- hosts: all - sudo: yes - tasks: - - - name: install nodejs + npm dependencies - apt: pkg={{ item }} state=present - with_items: - - nodejs - - npm - - - name: link nodejs binary correctly - file: src=/usr/bin/nodejs dest=/usr/bin/node state=link - - - name: install coffeescript + less dependencies - npm: name={{ item }} global=yes state=present - with_items: - - coffee-script - - less diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..ac0067f --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,9 @@ +--- +# tasks file for ansible-nginx-uwsgi-supervisor +- include: python.yaml +- include: nginx.yaml +- include: supervisor.yaml +- include: web_data_folders.yaml +- include: uwsgi.yaml + +# TODO Add in globally defined values for webapp and virtualenv folders diff --git a/pre_deployment/nginx.yaml b/tasks/nginx.yaml similarity index 100% rename from pre_deployment/nginx.yaml rename to tasks/nginx.yaml diff --git a/pre_deployment/python.yaml b/tasks/python.yaml similarity index 100% rename from pre_deployment/python.yaml rename to tasks/python.yaml diff --git a/pre_deployment/supervisor.yaml b/tasks/supervisor.yaml similarity index 100% rename from pre_deployment/supervisor.yaml rename to tasks/supervisor.yaml diff --git a/deployment/uwsgi.yaml b/tasks/uwsgi.yaml similarity index 100% rename from deployment/uwsgi.yaml rename to tasks/uwsgi.yaml diff --git a/pre_deployment/web_data_folders.yaml b/tasks/web_data_folders.yaml similarity index 100% rename from pre_deployment/web_data_folders.yaml rename to tasks/web_data_folders.yaml diff --git a/vars/main.yml b/vars/main.yml new file mode 100644 index 0000000..96727ee --- /dev/null +++ b/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for ansible-nginx-uwsgi-supervisor