-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy-quiz.yml
62 lines (52 loc) · 1.91 KB
/
deploy-quiz.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
- name: Client in PROD zone
hosts: newzone
tasks:
- name: Check if already deployed
debug:
msg: "Host {{ inventory_hostname }} is already deployed."
when: hostvars[inventory_hostname]['deployed'] | default(false) | bool
- name: End play if already deployed
meta: end_host
when: hostvars[inventory_hostname]['deployed'] | default(false) | bool
# Set up product Zone directory
- name: Remove /root/crucible-quiz if it exists
command: rm -rf /root/crucible-quiz
- name: Create /root/crucible-quiz
file:
path: /root/crucible-quiz
state: directory
# Prepare transfer of client code
- name: Compress client code
shell: |
rsync -av --exclude=dist --exclude=node_modules --exclude=yarn.lock --exclude=tests --exclude=.husky --exclude=.github --exclude=.git . client/ && \
rm -f client.tar.gz && \
tar -czvf client.tar.gz client
delegate_to: localhost
# Ensure no client codes file and directory exists when deploying starts
- name: Ensure no file client.tar.gz exists
file:
path: /root/crucible-quiz/client.tar.gz
state: absent
- name: Ensure no /root/crucible-quiz/client exists
file:
path: /root/crucible-quiz/client
state: absent
# Transfer client code to remote instance and set up client
- name: Transfer client code
copy:
src: client.tar.gz
dest: /root/crucible-quiz
- name: Uncompress the file in the remote instance
command: tar -xzf /root/crucible-quiz/client.tar.gz -C /root/crucible-quiz/
- name: Create client
shell: |
cd /root/crucible-quiz/client && \
yarn && \
yarn build && \
rm -rf /var/www/client && \
mkdir /var/www/client && \
cp -R dist/ /var/www/client/
- name: Restart Nginx service
systemd:
name: nginx
state: restarted