Skip to content

Instantly share code, notes, and snippets.

@clintonhalpin
Created February 21, 2017 20:59
Show Gist options
  • Save clintonhalpin/6933dd05b5e3d5cdf69aec954f1c2cfd to your computer and use it in GitHub Desktop.
Save clintonhalpin/6933dd05b5e3d5cdf69aec954f1c2cfd to your computer and use it in GitHub Desktop.
---
- hosts: all
tasks:
- include_vars: vars.yml
- name: install packages
apt: name={{ item }} update_cache=yes state=latest
with_items:
- git
- nginx
- vim
- nodejs
- npm
- fail2ban
- sphinxsearch
- rsync
- name: Local actions | remove entry from known hosts
command: sudo ssh-keygen -R {{ boxIp }}
delegate_to: "{{ hostIp }}"
- name: Create nodejs symlimk
shell: sudo ln -s /usr/bin/nodejs /usr/bin/node
become: yes
become_method: sudo
- name: Modify log permisions for nginx
shell: sudo chmod 755 /var/log/nginx/
- name: Remove default NGINX Confix
shell: sudo rm -rf /etc/nginx/sites-available/default && sudo rm -rf /etc/nginx/sites-enabled/default
- name: create vhost
template: src=templates/quote.conf dest=/etc/nginx/sites-enabled/quote.conf
- name: create vhost
template: src=templates/quote.conf dest=/etc/nginx/sites-available/quote.conf
- name: restart nginx
shell: service nginx restart
- name: copy over sphinx.conf
template: src=templates/sphinx.conf dest=/etc/sphinxsearch/sphinx.conf
- name: copy bashrc
template: src=templates/.bashrc dest=/home/vagrant/.bashrc
- name: Set MYSQL Install to quiet
shell: export DEBIAN_FRONTEND=noninteractive
- name: install mysql server
apt: name={{ item }} update_cache=yes state=latest
with_items:
- mysql-server-5.5
- name: install python mysql bindings
apt: name=python-mysqldb state=installed
become: yes
become_method: sudo
- name: configure mysql
mysql_db: name={{ db_name }} state=present
- name: configure mysql
shell: mysql -u {{ db_user }} -e "GRANT ALL PRIVILEGES ON {{ db_name }}.* TO 'quote'@'localhost' IDENTIFIED BY '{{ db_pass }}'"
- name: configure mysql
shell: mysql -u {{ db_user }} -e "FLUSH PRIVILEGES"
- name: install npm dependencies
shell: cd {{ app_root }} && npm i
- name: Create new DB
copy: src={{ db_sql_dump_path }} dest=/tmp/{{ db_dump_name }}.sql
- name: Create new DB
shell: mysql -u {{ db_user }} {{ db_name }} < /tmp/{{ db_dump_name }}.sql
- name: restart nginx
shell: service nginx restart
- name: create environment file
template: src=templates/.env.production.js dest={{ app_root }}etc/.env.production.js
- name: install npm
shell: npm install pm2 nodemon -g
- name: start app
shell: cd {{ app_root }} && NODE_ENV=production pm2 start server.js --name qc-fe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment