-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnginx.yml
67 lines (57 loc) · 1.8 KB
/
nginx.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
---
- name: Install nginx as reverse proxy for FastChat
hosts: gpu
become: true
vars:
admin_email: [email protected]
tasks:
- name: Add nginx, certbot packages
ansible.builtin.apt:
pkg:
- nginx
- certbot
- python3-certbot-nginx
- name: Copy site to nginx
ansible.builtin.template:
src: templates/site.j2
dest: /etc/nginx/sites-available/{{ inventory_hostname }}
owner: root
group: root
mode: '0644'
- name: Copy ssl-options to nginx
ansible.builtin.copy:
src: files/options-ssl-nginx.conf
dest: /etc/nginx
owner: root
group: root
mode: '0644'
- name: Check if cert dir already exists
ansible.builtin.stat:
path: /etc/letsencrypt/live/{{ inventory_hostname }}
register: cert_dir
- name: Stop nginx
ansible.builtin.systemd:
service: nginx.service
state: stopped
- name: Run certbot only on first run
ansible.builtin.command:
cmd: certbot certonly --standalone -d {{ inventory_hostname }} --agree-tos -m {{ admin_email }} -n
register: certbot_run
changed_when: certbot_run.rc != 0
when: not cert_dir.stat.exists
- name: Generate dhparams
ansible.builtin.command:
cmd: openssl dhparam -out /etc/nginx/ssl-dhparams.pem 2048
args:
creates: /etc/nginx/ssl-dhparams.pem
register: dhparam_gen
changed_when: dhparam_gen.rc != 0
- name: Create link to site config
ansible.builtin.file:
src: /etc/nginx/sites-available/{{ inventory_hostname }}
dest: /etc/nginx/sites-enabled/{{ inventory_hostname }}
state: link
- name: Start nginx
ansible.builtin.systemd:
service: nginx.service
state: started