From dbd43ecb7a371e654335c86d5438f49a3be0d2fd Mon Sep 17 00:00:00 2001 From: Jacob Cody Wimer Date: Wed, 27 Jan 2016 10:25:16 -0500 Subject: [PATCH] Separated workers and webservers --- roles/applicationvars/tasks/main.yml | 45 +++++++++++++++++++++++++ roles/common/tasks/main.yml | 2 +- roles/web/tasks/main.yml | 49 ++-------------------------- roles/worker/tasks/main.yml | 8 +++++ site.yml | 11 ++++++- 5 files changed, 66 insertions(+), 49 deletions(-) create mode 100644 roles/applicationvars/tasks/main.yml create mode 100644 roles/worker/tasks/main.yml diff --git a/roles/applicationvars/tasks/main.yml b/roles/applicationvars/tasks/main.yml new file mode 100644 index 0000000..cc22d6e --- /dev/null +++ b/roles/applicationvars/tasks/main.yml @@ -0,0 +1,45 @@ +--- +# This task puts all application variables in place for both workers and webservers +# + +- name: Create prod.env + shell: touch /var/www/html/prod.env + +- name: Declare env file + shell: echo export WRESTLINGDEV_ENV_FILE=/var/www/html/prod.env + +- name: Set env file permanently + shell: echo export WRESTLINGDEV_ENV_FILE=/var/www/html/prod.env >> /etc/environment + +- name: Set DB Name + shell: echo export WRESTLINGDEV_DB_NAME={{ lookup('env', 'WRESTLINGDEV_DB_NAME') }} >> /var/www/html/prod.env + +- name: Set db password + shell: echo export WRESTLINGDEV_DB_PWD={{ lookup('env', 'WRESTLINGDEV_DB_PWD') }} >> /var/www/html/prod.env + +- name: Set db host + shell: echo export WRESTLINGDEV_DB_HOST={{ lookup('env', 'WRESTLINGDEV_DB_HOST') }} >> /var/www/html/prod.env + +- name: Set db port + shell: echo export WRESTLINGDEV_DB_PORT={{ lookup('env', 'WRESTLINGDEV_DB_PORT') }} >> /var/www/html/prod.env + +- name: Set devise secret key + shell: echo export WRESTLINGDEV_DEVISE_SECRET_KEY={{ lookup('env', 'WRESTLINGDEV_DEVISE_SECRET_KEY') }} >> /var/www/html/prod.env + +- name: Set secret key base + shell: echo export WRESTLINGDEV_SECRET_KEY_BASE={{ lookup('env', 'WRESTLINGDEV_SECRET_KEY_BASE') }} >> /var/www/html/prod.env + +- name: Set new relic license + shell: echo export WRESTLINGDEV_NEW_RELIC_LICENSE_KEY={{ lookup('env', 'WRESTLINGDEV_NEW_RELIC_LICENSE_KEY') }} >> /var/www/html/prod.env + +- name: Set memcached username + shell: echo export MEMCACHIER_USERNAME={{ lookup('env', 'MEMCACHIER_USERNAME') }} >> /var/www/html/prod.env + +- name: Set memcached password + shell: echo export MEMCACHIER_PASSWORD={{ lookup('env', 'MEMCACHIER_PASSWORD') }} >> /var/www/html/prod.env + +- name: Set memcached servers + shell: echo export MEMCACHIER_SERVERS={{ lookup('env', 'MEMCACHIER_SERVERS') }} >> /var/www/html/prod.env + +- name: Set email password + shell: echo export WRESTLINGDEV_EMAIL_PWD={{ lookup('env', 'WRESTLINGDEV_EMAIL_PWD') }} >> /var/www/html/prod.env diff --git a/roles/common/tasks/main.yml b/roles/common/tasks/main.yml index 011a786..36ef4a3 100644 --- a/roles/common/tasks/main.yml +++ b/roles/common/tasks/main.yml @@ -1,5 +1,5 @@ --- -# This playbook contains playhs that will run on all nodes +# This playbook contains plays that will run on all nodes - name: Update apt apt: update_cache=yes diff --git a/roles/web/tasks/main.yml b/roles/web/tasks/main.yml index fd87bb8..730ca2b 100644 --- a/roles/web/tasks/main.yml +++ b/roles/web/tasks/main.yml @@ -1,54 +1,9 @@ --- -# These tasks are responsible for copying the latest dev/production code from -# # the version control system. -# +# This task clones the repo and runs the webserver docker container. + - name: Copy the code from repository git: repo={{ repository }} dest=/var/www/html/ -- name: Create prod.env - shell: touch /var/www/html/prod.env - -- name: Declare env file - shell: echo export WRESTLINGDEV_ENV_FILE=/var/www/html/prod.env - -- name: Set env file permanently - shell: echo export WRESTLINGDEV_ENV_FILE=/var/www/html/prod.env >> /etc/environment - -- name: Set DB Name - shell: echo export WRESTLINGDEV_DB_NAME={{ lookup('env', 'WRESTLINGDEV_DB_NAME') }} >> /var/www/html/prod.env - -- name: Set db password - shell: echo export WRESTLINGDEV_DB_PWD={{ lookup('env', 'WRESTLINGDEV_DB_PWD') }} >> /var/www/html/prod.env - -- name: Set db host - shell: echo export WRESTLINGDEV_DB_HOST={{ lookup('env', 'WRESTLINGDEV_DB_HOST') }} >> /var/www/html/prod.env - -- name: Set db port - shell: echo export WRESTLINGDEV_DB_PORT={{ lookup('env', 'WRESTLINGDEV_DB_PORT') }} >> /var/www/html/prod.env - -- name: Set devise secret key - shell: echo export WRESTLINGDEV_DEVISE_SECRET_KEY={{ lookup('env', 'WRESTLINGDEV_DEVISE_SECRET_KEY') }} >> /var/www/html/prod.env - -- name: Set secret key base - shell: echo export WRESTLINGDEV_SECRET_KEY_BASE={{ lookup('env', 'WRESTLINGDEV_SECRET_KEY_BASE') }} >> /var/www/html/prod.env - -- name: Set new relic license - shell: echo export WRESTLINGDEV_NEW_RELIC_LICENSE_KEY={{ lookup('env', 'WRESTLINGDEV_NEW_RELIC_LICENSE_KEY') }} >> /var/www/html/prod.env - -- name: Set memcached username - shell: echo export MEMCACHIER_USERNAME={{ lookup('env', 'MEMCACHIER_USERNAME') }} >> /var/www/html/prod.env - -- name: Set memcached password - shell: echo export MEMCACHIER_PASSWORD={{ lookup('env', 'MEMCACHIER_PASSWORD') }} >> /var/www/html/prod.env - -- name: Set memcached servers - shell: echo export MEMCACHIER_SERVERS={{ lookup('env', 'MEMCACHIER_SERVERS') }} >> /var/www/html/prod.env - -- name: Set email password - shell: echo export WRESTLINGDEV_EMAIL_PWD={{ lookup('env', 'WRESTLINGDEV_EMAIL_PWD') }} >> /var/www/html/prod.env - - name: Create and start apache docker image shell: cd /var/www/html/ && bash rails-prod.sh wrestlingdev-web -- name: Create and run delayed job worker - shell: cd /var/www/html/ && bash rails-worker-prod.sh wrestlingdev-worker diff --git a/roles/worker/tasks/main.yml b/roles/worker/tasks/main.yml new file mode 100644 index 0000000..38be4f7 --- /dev/null +++ b/roles/worker/tasks/main.yml @@ -0,0 +1,8 @@ +--- +# This task clones the repo and runs the worker docker container. +# +- name: Copy the code from repository + git: repo={{ repository }} dest=/var/www/html/ + +- name: Create and run delayed job worker + shell: cd /var/www/html/ && bash rails-worker-prod.sh wrestlingdev-worker diff --git a/site.yml b/site.yml index 294fe77..328c741 100644 --- a/site.yml +++ b/site.yml @@ -13,15 +13,24 @@ remote_user: root roles: + - applicationvars - web +- name: configure and deploy the rails workers and application code + hosts: workers + remote_user: root + + roles: + - applicationvars + - worker + - name: deploy first db and create cluster hosts: dbfirstclustermachine remote_user: root roles: - - firstdb - db + - firstdb - name: deploy mysql and configure database hosts: dbservers