-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplaybook.yaml
More file actions
140 lines (133 loc) · 4.16 KB
/
Copy pathplaybook.yaml
File metadata and controls
140 lines (133 loc) · 4.16 KB
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
- name: Install necessary dependencies
hosts: webservers
vars:
dns_and_reverse_proxies:
- domain: "34b446db-d550-4c6a-9e12-22f1f18bfd7e.pub.instances.scw.cloud"
present: true
caddy_served: true
port: 8000
ssl: true
- domain: "api.aoe2tools.net"
present: true
caddy_served: true
port: 8000
ssl: true
tasks:
- name: Ensure Caddy is at the latest version # noqa: package-latest
ansible.builtin.dnf:
name: caddy
state: latest
- name: Ensure uv is at the latest version # noqa: package-latest
ansible.builtin.dnf:
name: uv
state: latest
- name: Ensure unzip is at the latest version # noqa: package-latest
ansible.builtin.dnf:
name: unzip
state: latest
- name: Enable and start Caddy
ansible.builtin.systemd:
name: caddy
enabled: true
state: started
- name: Configure Caddy
when: item.present
block:
- name: Add proxy to Caddyfile
ansible.builtin.copy:
content: |
{% if not item.ssl %}http://{% endif %}{{ item.domain }} {
reverse_proxy :{{ item.port }}
encode
}
dest: /etc/caddy/Caddyfile.d/{{ item.domain }}.caddyfile
mode: "0644"
when: item.caddy_served
loop: "{{ dns_and_reverse_proxies }}"
- name: Reload Caddy
ansible.builtin.systemd:
name: caddy
state: reloaded
- name: Create Group
ansible.builtin.group:
name: web
- name: Create User
ansible.builtin.user:
name: web
state: present
group: web
shell: /bin/bash
- name: Create web root directory
ansible.builtin.file:
path: /var/www/app
state: directory
owner: web
group: web
mode: "0755"
- name: Create log directory
ansible.builtin.file:
path: /var/log/uvicorn
state: directory
owner: web
group: web
mode: "0755"
- name: Create systemd unit for FastAPI
ansible.builtin.copy:
content: |
[Unit]
Description=FastAPI uvicorn
After=network.target
[Service]
User=web
WorkingDirectory=/var/www/app/api-main
LimitNOFILE=4096
ExecStart=/usr/bin/uv run gunicorn app.main:app --workers 2 -k uvicorn.workers.UvicornWorker --bind 127.0.0.1:8000 --error-logfile /var/log/uvicorn/error_log.txt
Restart=on-failure
RestartSec=5s
[Install]
WantedBy=multi-user.target
dest: /etc/systemd/system/uvicorn.service
mode: "0644"
- name: Enable and start uvicorn
ansible.builtin.systemd_service:
name: uvicorn
enabled: true
state: started
- name: Reload systemd
ansible.builtin.systemd_service:
daemon_reload: true
- name: Download and decompress the latest aoe2ct API code
ansible.builtin.unarchive:
src: https://github.com/aoe2ct/api/archive/refs/heads/main.zip
dest: /var/www/app
remote_src: true
owner: web
group: web
mode: "0755"
- name: Install dependencies # noqa: no-changed-when
ansible.builtin.command: /usr/bin/uv sync --locked
become: true
become_user: web
args:
chdir: /var/www/app/api-main
- name: Create env file
ansible.builtin.copy:
content: |
SECRET_KEY={{ secret_key }}
DATABASE_URL={{ database_url }}
DISCORD_CLIENT_ID={{ discord_client_id }}
DISCORD_CLIENT_SECRET={{ discord_client_secret }}
FRONTEND_BASE_URL={{ frontend_base_url }}
TWITCH_CLIENT_ID={{ twitch_client_id }}
TWITCH_CLIENT_SECRET={{ twitch_client_secret }}
KICK_CLIENT_ID={{ kick_client_id }}
KICK_CLIENT_SECRET={{ kick_client_secret }}
YOUTUBE_API_KEY={{ youtube_api_key }}
dest: /var/www/app/api-main/.env
owner: web
group: web
mode: "0700"
- name: Restart uvicorn
ansible.builtin.systemd_service:
state: restarted
name: uvicorn