-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlive-helper-chat.yml
367 lines (307 loc) · 12 KB
/
live-helper-chat.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
# Install and configure the Live Helper Chat application on Centos 7.9
- name: Live Helper Chat Setup
hosts: localhost
become: yes
tasks:
# 0 - Disable ssh access and restart the ssh service
- name: Restarting sshd
shell: "sed -i 's/#Match User anoncvs/ForceCommand echo Please wait until the installation is completed..../g' /etc/ssh/sshd_config && systemctl restart sshd"
# 1 - Update the system
- name: Updating Packages
ansible.builtin.apt:
update_cache: yes
# 2 - Install PHP and dependencies
- name: Install PHP and dependencies
apt:
name: "{{ item }}"
state: present
with_items:
- php-json
- php-cli
- php-gd
- php-xml
- php-common
- php-pdo
- php-mysqlnd
- php-mbstring
- php
- php-bcmath
- php-imap
- php-geos
- php-fpm
- php-opcache
- git
- curl
- php-curl
- certbot
- python3-certbot-nginx
# 3 - Download and install Composer
- name: Download and install Composer
shell: curl -sS https://getcomposer.org/installer -o composer-setup.php
args:
chdir: /usr/local/src/
# 4 - Install Composer
- name: Install Composer
shell: sudo php /usr/local/src/composer-setup.php --install-dir=/usr/local/bin --filename=composer
# 5 - Install Nginx and screen
- name: Install Nginx and screen
apt:
name: nginx
state: latest
# 6 - Install MySQL server
- name: Install MySQL server
apt:
name: mysql-server
state: present
# 7 - Start MySQL service
- name: Start MySQL service
service:
name: mysql
state: started
enabled: yes
# 8 - Generate a random password
- name: Generate a random password
shell: >-
openssl rand -hex 14
register: mysql_root_pass
# 9 - copy the mysql root password to a file in /root/.mysql_root_pass
- name: copy the mysql root password to a file in /root/.mysql_root_pass
copy:
content: "{{ mysql_root_pass.stdout }}"
dest: /root/.mysql_root_pass
owner: root
group: root
mode: 0600
# 10 - Set the root password
- name: root | set root password
shell: >-
mysqladmin -u root
--password=''
password "{{mysql_root_pass.stdout}}"
# 11 - Create a .my.cnf file
- name: Create a .my.cnf file
file:
path: /root/.my.cnf
state: touch
owner: root
group: root
mode: 0600
# 12 - Add .my.cnf
- name: Add .my.cnf
lineinfile:
path: /root/.my.cnf
line: "{{ item }}"
with_items:
- "[client]"
- user=root
- password={{mysql_root_pass.stdout}}
# 13 - Reload privilege tables
- name: Reload privilege tables
command: 'mysql -ne "{{ item }}"'
with_items:
- FLUSH PRIVILEGES
changed_when: False
# 14 - Generate a random password for mysql user
- name: Generate a random password
shell: >-
openssl rand -hex 14
register: lhc_db_pass
# 15 - copy the mysql user password to a file in /root/.lhc_db_pass
- name: copy the mysql user password to a file in /root/.lhc_db_pass
copy:
content: "{{ lhc_db_pass.stdout }}"
dest: /root/.lhc_db_pass
owner: root
group: root
mode: 0600
# 16 - Add the lhc database and user
- name: Add the lhc database
command: 'mysql -ne "{{ item }}"'
with_items:
- CREATE database lhc;
- CREATE USER 'lhc'@'%' IDENTIFIED BY '{{lhc_db_pass.stdout}}';
- GRANT ALL PRIVILEGES ON lhc.* TO 'lhc'@'%';
- FLUSH PRIVILEGES;
# 17 - clone the Live Helper Chat application to /usr/local/src
- name: clone the Live Helper Chat application to /usr/local/src
shell: cd /usr/local/src/ && git clone https://github.com/LiveHelperChat/livehelperchat.git
# 18 - Remove nginx index.html from /var/www/html
- name: Remove nginx index.html from /var/www/html
file:
path: /var/www/html/{{ item }}
state: absent
with_items:
- index.html
- index.nginx-debian.html
# 19 - Move the content from /usr/local/src/livehelperchat/lhc_web to /var/www/html
- name: Move the content from /usr/local/src/livehelperchat/lhc_web to /var/www/html
shell: mv /usr/local/src/livehelperchat/lhc_web/* /var/www/html
# 20 - Update the 777 permission for the following directoy's
- name: Set directory permissions
command: chmod -R 777 "{{ item.path }}"
with_items:
- { path: '/var/www/html/settings/' }
- { path: '/var/www/html/var' }
- { path: '/var/www/html/cache' }
# 21 - Move /var/www/html/cli/install-cli.php to /var/www/html
- name: Move /var/www/html/cli/install-cli.php to /var/www/html
shell: mv /var/www/html/cli/install-cli.php /var/www/html
# 22 - Move /var/www/html/cli/example.settings.ini to /var/www/html/settings.ini
- name: Move /var/www/html/cli/example.settings.ini to /var/www/html/settings.ini
shell: mv /var/www/html/cli/example.settings.ini /var/www/html/settings.ini
# 23 - Update the mysql details in the /var/www/html/settings.ini
- name: Update database details in configuration file
lineinfile:
path: /var/www/html/settings.ini
regexp: "{{ item.regexp }}"
line: "{{ item.line }}"
state: present
with_items:
- { regexp: '^host = .*', line: 'host = localhost' }
- { regexp: '^user = .*', line: 'user = lhc' }
- { regexp: '^password = .*', line: 'password = "{{ lhc_db_pass.stdout }}"'}
- { regexp: '^database = .*', line: 'database = lhc' }
- { regexp: '^port = .*', line: 'port = 3306' }
# 24 - Install Node.js, npm and Redis
- name: Install Node.js
apt:
name: "{{ item }}"
state: present
with_items:
- nodejs
- npm
- redis
# 25 - Start Redis service
- name: Start Redis service
service:
name: redis
state: started
enabled: yes
# 26 - Clone the LiveHelperChat/NodeJS-Helper from git to /usr/local/src
- name: Clone the LiveHelperChat/NodeJS-Helper from git to /usr/local/src
shell: cd /usr/local/src/ && git clone https://github.com/LiveHelperChat/NodeJS-Helper.git
# 27 - Move the content from /usr/local/src/NodeJS-Helper to /var/www/html/extension
- name: Move the content from /usr/local/src/NodeJS-Helper to /var/www/html/extension
shell: mv /usr/local/src/NodeJS-Helper/nodejshelper /var/www/html/extension/
# 28 - Install composer dependencies from /var/www/html/extension/nodejshelper
- name: Install composer dependencies from /var/www/html/extension/nodejshelper
# shell: cd /var/www/html/extension/nodejshelper && composer install --no-interaction
command: composer install --no-interaction
args:
chdir: /var/www/html/extension/nodejshelper
environment:
HOME: /var/www/html/
# 29 - Install npm dependencies from /var/www/html/extension/nodejshelper/serversc/lhc
- name: Install npm dependencies from /var/www/html/extension/nodejshelper/serversc/lhc
shell: cd /var/www/html/extension/nodejshelper/serversc/lhc && npm install
# 30 - Copy the secret hash from /var/www/html/settings/settings.ini.php
- name: Retrieve secret hash from settings.ini.php
shell: grep "secrethash" /var/www/html/settings/settings.ini.php | cut -d "'" -f 4
register: secret_hash_result
# 31 - Update secret hash in server.js
- name: Update secret hash in server.js
replace:
path: /var/www/html/extension/nodejshelper/serversc/lhc/server.js
regexp: "secretHash: '<use_your_secret_hash>'"
replace: "secretHash: '{{ secret_hash_result.stdout }}'"
backup: yes
# 32 - Make a copy make copy of /var/www/html/extension/nodejshelper/settings/settings.ini.default.php to /var/www/html/extension/nodejshelper/settings/settings.ini.default.php
- name: Make a copy of settings.ini.default.php
copy:
src: /var/www/html/extension/nodejshelper/settings/settings.ini.default.php
dest: /var/www/html/extension/nodejshelper/settings/settings.ini.php
# 33 - Clone the LiveHelperChat/lhc-php-resque to /usr/local/src
- name: Clone the LiveHelperChat/lhc-php-resque to /usr/local/src
shell: cd /usr/local/src/ && git clone https://github.com/LiveHelperChat/lhc-php-resque.git
# 34 - Move the directory from /usr/local/src/lhc-php-resque/lhcphpresque to /var/www/html/extension/
- name: Move the directory from /usr/local/src/lhc-php-resque/lhcphpresque to /var/www/html/extension/
shell: mv /usr/local/src/lhc-php-resque/lhcphpresque /var/www/html/extension/
# # 35 - clone the configuration to /usr/local/src
# - name: clone the Live Helper Chat application to /opt/live-helper
# shell: cd /usr/local/src && git clone https://github.com/vigneshvrm/Workout.git
# 36 - copy the nginx configuration jinja2 template from /opt/live-helper/Workout/livehelperchat.conf.j2 to /etc/nginx/conf.d
- name: copy the nginx configuration jinja2 template
copy:
src: /usr/local/src/Workout/livehelperchat.conf
dest: /etc/nginx/conf.d/
remote_src: yes
# 37 - Copy the resque.php from /var/www/html/extension/lhcphpresque/doc/resque.php to /var/www/html/
- name: Copy the resque.php
copy:
src: /var/www/html/extension/lhcphpresque/doc/resque.php
dest: /var/www/html/
follow: yes
# 38 - Install composer dependencies from /var/www/html/extension/lhcphpresque
- name: Install composer dependencies from /var/www/html/extension/lhcphpresque/doc/resque.php
# shell: cd /var/www/html/extension/lhcphpresque && composer update
command: composer update --no-interaction
args:
chdir: /var/www/html/extension/lhcphpresque
environment:
HOME: /var/www/html/
# 39 - Add cron job for lhcphpresque at reboot
- name: Add cron job for lhcphpresque at reboot
cron:
name: "Run lhcphpresque at reboot"
special_time: reboot
job: "cd /var/www/web/extension/lhcphpresque/doc/ && ./phpresque.sh >> /dev/null 2>&1"
# 40 - Add cron job to create runresque.lock
- name: Add cron job to create runresque.lock
cron:
name: "Create runresque.lock"
minute: "40"
hour: "7"
job: "/bin/touch /var/www/web/extension/lhcphpresque/doc/runresque.lock > /dev/null 2>&1"
# 41 - Add cron job for resque.sh
- name: Add cron job for resque.sh
cron:
name: "Run resque.sh every minute"
job: "cd /var/www/web/extension/lhcphpresque/doc && ./resque.sh >> /dev/null 2>&1"
# 42 - Add cron job for nodejshelper restart
- name: Add cron job for nodejshelper restart
cron:
name: "Restart nodejshelper daily"
minute: "1"
hour: "1"
job: "/usr/sbin/service nodejshelper restart > /dev/null 2>&1"
# 43 - change owner ship of /var/www/html
- name: change owner ship of /var/www/html
shell: chown -R www-data. /var/www/html
# 43.1 - Stop apache2 service
- name: Stop apache2 service
service:
name: apache2
state: stopped
# 44 - copy the nodejshelper.service from /usr/local/src/Workout/nodejshelper.service to /etc/systemd/system
- name: copy the nodejshelper.service
copy:
src: /usr/local/src/Workout/nodejshelper.service
dest: /etc/systemd/system/
remote_src: yes
# 45 - restart Nginx
- name: restart Nginx
service:
name: nginx
state: restarted
# 46 - create a cloudstack directory
- name: Creating a directory for shell script
ansible.builtin.file:
path: /opt/cloudstack
state: directory
# 47 - copy the shell script from /opt/live-helper/Workout/live-helper.sh to /opt/cloudstack
- name: Copy files for shell script
copy:
src: "{{ item.confsrc }}"
dest: "{{ item.confdest }}"
remote_src: yes
with_items:
- { confsrc: '/usr/local/src/Workout/live-helper.sh', confdest: '/opt/cloudstack/'}
# 48 - Add the shell script to .bashrc
- name: Adding a line for shell script
lineinfile:
path: /root/.bashrc
line: "chmod +x /opt/cloudstack/live-helper.sh && /opt/cloudstack/live-helper.sh"
state: present
# 49 - Enable the ssh acess and restart the sshd service
- name: Restarting sshd
shell: "sed -i 's/ForceCommand echo Please wait until the installation is completed..../#Match User anoncvs/g' /etc/ssh/sshd_config && systemctl restart sshd"