Skip to content

Commit c18dff2

Browse files
committed
Fixes for static web files (do not use template) + renew script.
1 parent 6f74fab commit c18dff2

File tree

3 files changed

+62
-5
lines changed

3 files changed

+62
-5
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,17 @@ create an alterate setup:
131131
* / will refer to what you place in `www/yourdomain.tld/files/`
132132
* /~user will refer to what you place in `www/yourdomain.tld/people/user/`
133133

134+
Any text files placed in the `files/` or `people` subdirectories of
135+
`www/yourdomain.tld` will be installed using the `jinja2` template
136+
copy, enabling you to use variables like `{{ domain_name }}` in
137+
your files.
138+
139+
Occasionally, this template mechanism does not work well (javascript
140+
source code, for example). To work around this, if you place
141+
files in a `static/` subtree, they will be copied without
142+
templating. Place files in `static/files/` and `static/people/user` to
143+
have them installed in the correct places.
144+
134145
Note that files placed in `www/` are ignored by git and will have
135146
to be backed up.
136147

roles/certificates/files/renew

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/bin/sh
22
c=/usr/local/bin/certbot
3+
d=/usr/local/bin/docker-compose
34

45
LIMIT=5
56
DAYS=$($c certificates 2>/dev/null |
@@ -14,9 +15,9 @@ then
1415
else
1516
if [ $DAYS -lt $LIMIT ]; then
1617
cd /home/{{ deploy_user_name }}
17-
docker-compose stop nginx > $msg 2>&1
18+
$d stop nginx > $msg 2>&1
1819
$c renew >> $msg 2>&1
19-
docker-compose start nginx >> $msg 2>&1
20+
$d start nginx >> $msg 2>&1
2021
SUBJECT="Cert Renewal Attempt (Valid for $DAYS days)"
2122
else
2223
SUBJECT="Cert is still valid (for $DAYS days)"

roles/mailserver/tasks/main.yml

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,35 +230,71 @@
230230

231231
- name: Set up www site with files.
232232
block:
233+
- local_action:
234+
module: file
235+
path: www/{{ domain_name }}/{{ item }}
236+
args:
237+
state: directory
238+
with_items:
239+
- static
240+
- people
241+
- files
242+
become: false
233243
# now create dirs under /mnt/docker/www
244+
- file:
245+
path: /mnt/docker/www/files/{{ item.path }}
246+
state: directory
247+
recurse: yes
248+
owner: 991
249+
group: 991
250+
with_filetree: www/{{ domain_name}}/files
251+
when: item.state == 'directory'
252+
- file:
253+
path: /mnt/docker/www/people/{{ item.path }}
254+
state: directory
255+
recurse: yes
256+
owner: 991
257+
group: 991
258+
with_filetree: www/{{ domain_name}}/people
259+
when: item.state == 'directory'
234260
- file:
235261
path: /mnt/docker/www/{{ item.path }}
236262
state: directory
237263
recurse: yes
238264
owner: 991
239265
group: 991
240-
with_filetree: www/{{ domain_name}}
266+
with_filetree: www/{{ domain_name}}/static
241267
when: item.state == 'directory'
242268

243269
# list of text files
244270
- local_action:
245271
module: |
246-
shell find . -type f | xargs file -i |
272+
shell find . -type f | egrep -v '^\./static/' | xargs file -i |
247273
egrep 'text/plain|text/html' | awk -F: '{print $1}'
248274
args:
249275
chdir: www/{{ domain_name }}
250276
register: web_text_files
251277
changed_when: false
278+
252279
# list of binary files
253280
- local_action:
254281
module: |
255-
shell find . -type f | xargs file -i |
282+
shell find . -type f | egrep -v '^./static/' | xargs file -i |
256283
egrep -v 'text/plain|text/html' | awk -F: '{print $1}'
257284
args:
258285
chdir: www/{{ domain_name }}
259286
register: web_binary_files
260287
changed_when: false
261288

289+
# list of static files
290+
- local_action:
291+
module: |
292+
shell find . -type f
293+
args:
294+
chdir: www/{{ domain_name }}/static
295+
register: web_static_files
296+
changed_when: false
297+
262298
# now create files with template
263299
- name: Update web site text files
264300
template:
@@ -277,6 +313,15 @@
277313
group: 991
278314
with_items: "{{ web_binary_files.stdout_lines }}"
279315

316+
# Copy the static files
317+
- name: Update web site static files
318+
copy:
319+
src: www/{{ domain_name }}/static/{{ item }}
320+
dest: /mnt/docker/www/{{ item }}
321+
owner: 991
322+
group: 991
323+
with_items: "{{ web_static_files.stdout_lines }}"
324+
280325
# Now for the website nginx config
281326
- name: Set up the nginx config
282327
template:

0 commit comments

Comments
 (0)