-
Notifications
You must be signed in to change notification settings - Fork 0
/
provision.yml
114 lines (96 loc) · 2.96 KB
/
provision.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
- name: Update and upgrade apt packages
hosts: all
remote_user: deploy
become: yes
tasks:
- name: Update apt repo and cache
apt:
update_cache: yes
force_apt_get: yes
cache_valid_time: 3600
- name: Upgrade all packages
apt:
upgrade: dist
force_apt_get: yes
- name: Check if a reboot is needed
register: reboot_required_file
stat:
path: /var/run/reboot-required
- name: Reboot the server if kernel updated
reboot:
msg: "Reboot initiated by Ansible for kernel updates"
connect_timeout: 5
reboot_timeout: 300
pre_reboot_delay: 0
post_reboot_delay: 30
test_command: uptime
when: reboot_required_file.stat.exists
- name: Install packages
hosts: all
remote_user: deploy
become: true
tasks:
- name: Install system packages with apt
register: updatesys
apt:
update_cache: yes
name:
- curl
- gnupg
- ufw
- nginx
- python3-certbot-nginx
state: present
- name: Enable ufw firewall
community.general.ufw:
state: enabled
- community.general.ufw:
rule: allow
name: OpenSSH
- community.general.ufw:
rule: allow
name: "Nginx Full"
- name: Create directory for the app
file: path=/home/{{domain}}
state=directory
owner=deploy
group=deploy
- name: Copy nginx conf to server
template: src=./templates/nginx.conf
dest=/etc/nginx/sites-available/{{ domain }}.conf
- name: Create symlink to new nginx conf
file: src=/etc/nginx/sites-available/{{ domain }}.conf
dest=/etc/nginx/sites-enabled/{{ domain }}.conf
state=link
- name: Create ssl certificate with certbot
shell: "sudo certbot --nginx -d {{ domain }} --agree-tos --email {{ email }} --non-interactive"
notify: Restart nginx
- name: Copy systemd service to server
template: src=./templates/systemd.service
dest=/lib/systemd/system/{{ domain }}.service
- name: Copy systemd friendly start script to server
template:
src: ./templates/start.sh
dest: /home/{{ domain }}/start.sh
mode: +x
- name: Reload and enable systemd service
shell: "sudo systemctl daemon-reload && sudo systemctl enable --now {{ domain }} && sudo systemctl start {{ domain }}"
handlers:
- name: Restart nginx
service:
name: nginx
state: restarted
- name: Install node and the app
hosts: all
remote_user: deploy
tasks:
- name: Install nvm
shell: >
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
args:
creates: "{{ ansible_env.HOME }}/.nvm/nvm.sh"
- name: Install node and set version
shell: >
source ~/.nvm/nvm.sh && nvm install {{ nodejs_version }} && nvm use {{ nodejs_version }}
args:
executable: /bin/bash