From 1771165636bf815ee6c305c11a55e3379ef981c0 Mon Sep 17 00:00:00 2001 From: Jacob Cody Wimer Date: Thu, 14 Jan 2016 08:46:55 -0500 Subject: [PATCH] Getting shell set up --- README.md | 3 ++ deploy-site.sh | 55 ++++++++++++++++++++++++++++ group_vars/all | 6 ++++ group_vars/dbservers | 9 +++++ hosts | 12 +++++++ roles/common/tasks/main.yml | 71 +++++++++++++++++++++++++++++++++++++ roles/web/tasks/main.yml | 51 ++++++++++++++++++++++++++ site.yml | 30 ++++++++++++++++ 8 files changed, 237 insertions(+) create mode 100644 deploy-site.sh create mode 100644 group_vars/all create mode 100644 group_vars/dbservers create mode 100644 hosts create mode 100644 roles/common/tasks/main.yml create mode 100644 roles/web/tasks/main.yml create mode 100644 site.yml diff --git a/README.md b/README.md index ec6d758..556afd0 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,5 @@ # wrestlingdev-ansible Deploy wrestlingdev infrastructure + +Deploy the entire stack: +ansible-playbook -i hosts site.yml diff --git a/deploy-site.sh b/deploy-site.sh new file mode 100644 index 0000000..eba726a --- /dev/null +++ b/deploy-site.sh @@ -0,0 +1,55 @@ +if [ -z ${WRESTLINGDEV_DB_NAME} ]; then + echo "WRESTLINGDEV_DB_NAME not set" + exit +fi + +if [ -z ${WRESTLINGDEV_DB_USER} ]; then + echo "WRESTLINGDEV_DB_USER not set" + exit +fi + +if [ -z ${WRESTLINGDEV_DB_PWD} ]; then + echo "WRESTLINGDEV_DB_PWD not set" + exit +fi + +if [ -z ${WRESTLINGDEV_DB_HOST} ]; then + echo "WRESTLINGDEV_DB_HOST not set" + exit +fi + +if [ -z ${WRESTLINGDEV_DB_PORT} ]; then + echo "WRESTLINGDEV_DB_PORT not set" + exit +fi + +if [ -z ${WRESTLINGDEV_DEVISE_SECRET_KEY} ]; then + echo "WRESTLINGDEV_DEVISE_SECRET_KEY not set" + exit +fi + +if [ -z ${WRESTLINGDEV_SECRET_KEY_BASE} ]; then + echo "WRESTLINGDEV_SECRET_KEY_BASE not set" + exit +fi + +if [ -z ${WRESTLINGDEV_NEW_RELIC_LICENSE_KEY} ]; then + echo "WRESTLINGDEV_NEW_RELIC_LICENSE_KEY not set" + exit +fi + +if [ -z ${MEMCACHIER_PASSWORD} ]; then + echo "MEMCACHIER_PASSWORD not set" + exit +fi + +if [ -z ${MEMCACHIER_SERVERS} ]; then + echo "MEMCACHIER_SERVERS not set" + exit +fi + +if [ -z ${MEMCACHIER_USERNAME} ]; then + echo "MEMCACHIER_USERNAME not set" + exit +fi + diff --git a/group_vars/all b/group_vars/all new file mode 100644 index 0000000..16aed27 --- /dev/null +++ b/group_vars/all @@ -0,0 +1,6 @@ +--- +# Variables listed here are applicable to all host groups + +repository: https://github.com/jcwimer/wrestlingApp.git + +firstdbhostname: {{ groups[['dbservers'][0]] }} diff --git a/group_vars/dbservers b/group_vars/dbservers new file mode 100644 index 0000000..027a32a --- /dev/null +++ b/group_vars/dbservers @@ -0,0 +1,9 @@ +--- +# The variables file used by the playbooks in the dbservers group. +# These don't have to be explicitly imported by vars_files: they are autopopulated. + +mysqlservice: mysqld +mysql_port: 3306 +dbuser: foouser +dbname: foodb +upassword: abc diff --git a/hosts b/hosts new file mode 100644 index 0000000..9aceee1 --- /dev/null +++ b/hosts @@ -0,0 +1,12 @@ +[webservers] +webhostname + +[dbfirstclustermachine] +db1-hostname + +[dbservers] +db2-hostname +db3-hostname + +[haproxy] +haproxy-hostname diff --git a/roles/common/tasks/main.yml b/roles/common/tasks/main.yml new file mode 100644 index 0000000..1b7a252 --- /dev/null +++ b/roles/common/tasks/main.yml @@ -0,0 +1,71 @@ +--- +# This playbook contains playhs that will run on all nodes + +- name: Update apt + apt: update_cache=yes + +- name: Upgrade APT to the lastest packages + apt: upgrade=safe + +- name: Install htop + apt: name=htop state=present + +- name: Install curl + apt: name=curl state=present + +- name: Install openssh-server + apt: name=openssh-server state=present + +- name: Install git + apt: name=git state=present + +- name: Install tmux + apt: name=tmux state=prsent + +- name: Install zip + apt: name=zip state=present + +- name: Install unzip + apt: name=unzip state=present + +- name: Install fail2ban + apt: name=fail2ban state=present + +- name: Install ntp + apt: name=ntp state=present + +- name: Install mysql-client + apt: name=mysql-client state=present + +- name: Install wget + apt: name=wget state=present + +- name: Set git username + shell: git config --global user.name "Jacob Cody Wimer" + +- name: Set git email + shell: git config --global user.email "jacob.wimer@gmail.com" + +- name: Get docker + shell: curl -sSL https://get.docker.com/ | sh + +- name: Get docker compose + shell: curl -L https://github.com/docker/compose/releases/download/1.5.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose + +- name: Link docker compose + shell: chmod +x /usr/local/bin/docker-compose + +- name: Set timezone to NewYork + shell: timedatectl set-timezone America/New_York + +- name: Install heroku toolbelt + shell: wget -O- https://toolbelt.heroku.com/install-ubuntu.sh | sh + +- name: Create update script + shell: touch /etc/cron.daily/update.sh + +- name: Set update script as executable + shell: chmod +x /etc/cron.daily/update.sh + +- name: Add update line to update script + shell: echo apt-get update && apt-get upgrade -y && apt-get clean && apt-get autoclean && apt-get autoremove -y && apt-get update >> /etc/cron.daily/update.sh diff --git a/roles/web/tasks/main.yml b/roles/web/tasks/main.yml new file mode 100644 index 0000000..446b96b --- /dev/null +++ b/roles/web/tasks/main.yml @@ -0,0 +1,51 @@ +--- +# These tasks are responsible for copying the latest dev/production code from +# # the version control system. +# +- 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: 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/site.yml b/site.yml new file mode 100644 index 0000000..9353146 --- /dev/null +++ b/site.yml @@ -0,0 +1,30 @@ +-- +# This playbook deploys the whole application stack for wrestlingdev +# +- name: apply common configuration to all nodes + hosts: all + remote_user: root + + roles: + - common + +- name: configure and deploy the webservers and application code + hosts: webservers + remote_user: root + + roles: + - web + +- name: deploy first db and create cluster + hosts: dbfirstclustermachine + remote_user: root + + roles: + - firstdb + +- name: deploy mysql and configure database + hosts: dbservers + remote_user: root + + roles: + - db