-
Notifications
You must be signed in to change notification settings - Fork 2
/
deploy_server.yml
152 lines (126 loc) · 4.49 KB
/
deploy_server.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
---
- hosts: server_nodes
become: yes
vars:
node_version: 8
database_password: "{{ lookup('env', 'DATABASE_PASSWORD')}}"
database_name: deployment
gmail_username: "{{ lookup('env', 'ROBOCOP_GMAIL_USERNAME')}}"
gmail_password: "{{ lookup('env', 'ROBOCOP_GMAIL_PASSWORD')}}"
ROBOCOP_PRIVATE_KEY: "{{ lookup('env', 'ROBOCOP_PRIVATE_KEY')}}"
tasks:
- name: Add Nodesource Keys
become: yes
apt_key:
url: http://deb.nodesource.com/gpgkey/nodesource.gpg.key
state: present
# Note: "xenial" is ubuntu-speak for 16.04
- name: Add Nodesource Apt Sources
become: yes
apt_repository:
repo: '{{ item }}'
state: present
with_items:
- 'deb http://deb.nodesource.com/node_6.x xenial main'
- 'deb-src http://deb.nodesource.com/node_6.x xenial main'
- name: Install NodeJS and NPM
become: yes
apt:
name: nodejs
state: latest
update_cache: yes
- name: Install forever
become: yes
update_cache: yes
npm:
name: forever
global: yes
state: present
- name: Install mysql2
become: yes
update_cache: yes
npm:
name: mysql2
global: yes
state: present
- name: Install git
apt: pkg=git state=present update_cache=yes
become: yes
- name: "Ensure Services are running the latest version"
apt:
name: "{{ item }}"
state: latest
with_items:
- bash
- openssl
- openssh-client
- openssh-server
- name: "Cleanup /tmp/*"
shell: /bin/rm -rf /tmp/*
- name: Set MySQL root password before installing
debconf: name='mysql-server' question='mysql-server/root_password' value='{{database_password | quote}}' vtype='password'
- name: Confirm MySQL root password before installing
debconf: name='mysql-server' question='mysql-server/root_password_again' value='{{database_password | quote}}' vtype='password'
- name: Install MySQL
apt:
name: "{{ item }}"
with_items:
- python-mysqldb
- mysql-server
- name: Copy the root credentials as .my.cnf file
template: src=root.cnf.j2 dest=~/.my.cnf mode=0600
- name: Create Mysql Database
mysql_db: name={{ database_name }} state=present
- name: creating source directory"
file:
path: "/home/vagrant/SecurityBot"
state: directory
recurse: yes
become: yes
- file:
path: "/home/vagrant/SecurityBot"
mode: 0777
state: directory
become: yes
- name: Clone git repo
update_cache: yes
git:
name: https://github.com/goeltanmay/SecurityBot.git
clone: yes
dest: "/home/vagrant/SecurityBot"
- name: Adding the path in the bashrc files
lineinfile: dest=/home/vagrant/.bashrc line='export CLEARDB_DATABASE_URL=mysql://root:{{ database_password }}@localhost:3306/{{ database_name }}' state=present
# # - name: Install npm deps
# # become: yes
# # npm:
# # path: "/home/vagrant/SecurityBot"
# # state: present
# #
- name: npm install command
command: sudo npm install chdir=/home/vagrant/SecurityBot/
async: 1000
poll: 0
register: npm_install
environment:
npm_config_loglevel: silent
- name: 'npm install long running'
async_status: jid={{ npm_install.ansible_job_id }}
register: job_result
until: job_result.finished
retries: 30
- name: Install sequelize-cli
command: sudo npm install -g sequelize-cli
- name: Run sequelize migrations
command: sequelize db:migrate chdir=/home/vagrant/SecurityBot/
environment:
CLEARDB_DATABASE_URL: mysql://root:{{ database_password }}@localhost:3306/{{ database_name }}
NODE_ENV: production
- name: Run the instance
command : forever start /home/vagrant/SecurityBot/main.js
environment:
CLEARDB_DATABASE_URL: mysql://root:{{ database_password }}@localhost:3306/{{ database_name }}
NODE_ENV: production
gmail_username: "{{ gmail_username }}"
gmail_password: "{{ gmail_password }}"
ROBOCOP_PRIVATE_KEY: "{{ ROBOCOP_PRIVATE_KEY }}"
# - name: setup other environment variables