Skip to content

Commit e67accf

Browse files
committed
fix: added missing envs, ansible fixes and modernization, FAQ updates
1 parent 68de75a commit e67accf

34 files changed

+90499
-74786
lines changed

.env.defaults

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
SSL_CERT_PATH=
2+
SSL_KEY_PATH=
3+
SSL_CA_PATH=
4+
BACKUP_SECRET=
15
MONGO_BACKUP_BUCKET=forwardemail-backups
26
REDIS_BACKUP_BUCKET=forwardemail-backups
37
REDIS_DATA_DIR=/var/lib/redis

ansible/docs/README_MONGO_REDIS.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ ansible-galaxy install -r ansible/requirements.yml
7373

7474
This installs:
7575
- `trfore.mongodb_install` v3.0.5 - MongoDB installation
76-
- `geerlingguy.redis` v1.9.0 - Redis installation
7776

7877
### Environment Variables
7978

ansible/playbooks/certificates.yml

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,40 @@
22
# SPDX-License-Identifier: BUSL-1.1
33

44
---
5-
- hosts: all
5+
# mail mongo and redis don't need this
6+
- hosts: imap:pop3:smtp:http:bree:sqlite:mx1:mx2
67
name: Certificates
78
vars_prompt:
89
- name: input_key
9-
prompt: Enter path to certificate private key file (e.g. /path/to/.ssl-key)
10+
prompt: "Enter path to certificate private key file (e.g. /path/to/.ssl-key) [REQUIRED]"
1011
private: false
1112
- name: input_cert
12-
prompt: Enter path to certificate full chain/certificate file (e.g. /path/to/.ssl-cert)
13+
prompt: "Enter path to certificate full chain/certificate file (e.g. /path/to/.ssl-cert) [REQUIRED]"
1314
private: false
1415
- name: input_bundle
15-
prompt: "Optional: Leave blank or enter path to certificate CA bundle file (e.g. /path/to/.ssl-ca)"
16+
prompt: "Enter path to certificate CA bundle file (e.g. /path/to/.ssl-ca) [REQUIRED]"
1617
private: false
1718
- name: input_apple_key
1819
prompt: "Optional: Leave blank or enter path to Apple K8 certificate key file (e.g. /path/to/AuthKey_00000000000.p8)"
1920
private: false
2021

2122
tasks:
23+
# Validate required inputs
24+
- name: Fail if key path is empty
25+
fail:
26+
msg: "Certificate private key path is required. Please re-run the playbook and provide a valid path."
27+
when: (input_key is not defined) or (input_key | length == 0)
28+
29+
- name: Fail if cert path is empty
30+
fail:
31+
msg: "Certificate file path is required. Please re-run the playbook and provide a valid path."
32+
when: (input_cert is not defined) or (input_cert | length == 0)
33+
34+
- name: Fail if bundle path is empty
35+
fail:
36+
msg: "CA bundle file path is required. Please re-run the playbook and provide a valid path."
37+
when: (input_bundle is not defined) or (input_bundle | length == 0)
38+
2239
# key file
2340
- name: Check if key file exists
2441
local_action: stat path={{ input_key }}
@@ -45,12 +62,11 @@
4562
local_action: stat path={{ input_bundle }}
4663
register: local_bundle_file
4764
become: false
48-
when: (input_bundle is defined) and (input_bundle | length > 0)
4965

5066
- name: Fail when local bundle file does not exist
5167
fail:
5268
msg: "bundle file does not exist: {{ input_bundle }}"
53-
when: (input_bundle is defined) and (input_bundle | length > 0) and (not local_bundle_file.stat.exists)
69+
when: not local_bundle_file.stat.exists
5470

5571
# apple_key file
5672
- name: Check if apple_key file exists
@@ -101,7 +117,6 @@
101117
owner: deploy
102118
# https://chmodcommand.com/chmod-660/
103119
mode: "0660"
104-
when: (input_bundle is defined) and (input_bundle | length > 0)
105120

106121
# copy local apple_key
107122
- name: Copy local apple_key file to server

ansible/playbooks/env.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
# SPDX-License-Identifier: BUSL-1.1
33

44
---
5-
- hosts: all
5+
# mail mongo and redis don't need this
6+
- hosts: imap:pop3:smtp:http:bree:sqlite:mx1:mx2
67
name: Env
78
vars:
89
env_path: "{{ inventory_dir }}/.env.production"

ansible/playbooks/mongo.yml

Lines changed: 68 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,68 @@
88
import_playbook: ssh-keys.yml
99

1010
- hosts: mongo
11-
name: Prepare for certificates
12-
become: true
13-
become_user: root
11+
name: Certificate Paths
12+
vars_prompt:
13+
- name: input_key
14+
prompt: "Enter path to certificate private key file on local machine (e.g. /path/to/.ssl-key) [REQUIRED]"
15+
private: false
16+
- name: input_cert
17+
prompt: "Enter path to certificate full chain/certificate file on local machine (e.g. /path/to/.ssl-cert) [REQUIRED]"
18+
private: false
19+
- name: input_ca
20+
prompt: "Enter path to certificate CA bundle file on local machine (e.g. /path/to/.ssl-ca) [REQUIRED]"
21+
private: false
1422
tasks:
15-
- name: Ensure /var/www/production directory exists for certificates
16-
file:
17-
path: /var/www/production
18-
state: directory
19-
owner: deploy
20-
group: deploy
21-
mode: "0755"
22-
23-
- name: Import certificates playbook
24-
import_playbook: certificates.yml
23+
- name: Fail if key path is empty
24+
fail:
25+
msg: "Certificate private key path is required. Please re-run the playbook and provide a valid path."
26+
when: (input_key is not defined) or (input_key | length == 0)
27+
28+
- name: Fail if cert path is empty
29+
fail:
30+
msg: "Certificate file path is required. Please re-run the playbook and provide a valid path."
31+
when: (input_cert is not defined) or (input_cert | length == 0)
32+
33+
- name: Fail if CA path is empty
34+
fail:
35+
msg: "CA bundle file path is required. Please re-run the playbook and provide a valid path."
36+
when: (input_ca is not defined) or (input_ca | length == 0)
37+
38+
- name: Check if key file exists locally
39+
local_action: stat path={{ input_key }}
40+
become: false
41+
register: local_key_file
42+
43+
- name: Fail when local key file does not exist
44+
fail:
45+
msg: "key file does not exist: {{ input_key }}"
46+
when: not local_key_file.stat.exists
47+
48+
- name: Check if cert file exists locally
49+
local_action: stat path={{ input_cert }}
50+
become: false
51+
register: local_cert_file
52+
53+
- name: Fail when local cert file does not exist
54+
fail:
55+
msg: "cert file does not exist: {{ input_cert }}"
56+
when: not local_cert_file.stat.exists
57+
58+
- name: Check if CA file exists locally
59+
local_action: stat path={{ input_ca }}
60+
become: false
61+
register: local_ca_file
62+
63+
- name: Fail when local CA file does not exist
64+
fail:
65+
msg: "CA file does not exist: {{ input_ca }}"
66+
when: not local_ca_file.stat.exists
67+
68+
- name: Store certificate paths as facts
69+
set_fact:
70+
ssl_key_path: "{{ input_key }}"
71+
ssl_cert_path: "{{ input_cert }}"
72+
ssl_ca_path: "{{ input_ca }}"
2573

2674
- hosts: mongo
2775
name: Hostname
@@ -33,9 +81,6 @@
3381
that:
3482
- lookup('env', 'MONGO_HOST') != ''
3583
- lookup('env', 'MONGO_PORT') != ''
36-
- lookup('env', 'SSL_CERT_PATH') != ''
37-
- lookup('env', 'SSL_KEY_PATH') != ''
38-
- lookup('env', 'SSL_CA_PATH') != ''
3984
- lookup('env', 'AWS_ACCESS_KEY_ID') != ''
4085
- lookup('env', 'AWS_SECRET_ACCESS_KEY') != ''
4186
- lookup('env', 'AWS_ENDPOINT_URL') != ''
@@ -184,32 +229,30 @@
184229
group: mongodb
185230
mode: "0750"
186231

187-
- name: Copy SSL certificate from /var/www/production to MongoDB directory
232+
# Copy SSL certificates directly from local machine to MongoDB directory
233+
- name: Copy SSL certificate to MongoDB directory
188234
copy:
189-
src: "{{ lookup('env', 'SSL_CERT_PATH') }}"
235+
src: "{{ hostvars[inventory_hostname]['ssl_cert_path'] }}"
190236
dest: /etc/mongodb/ssl/mongodb.crt
191237
owner: mongodb
192238
group: mongodb
193239
mode: "0400"
194-
remote_src: yes
195240

196-
- name: Copy SSL private key from /var/www/production to MongoDB directory
241+
- name: Copy SSL private key to MongoDB directory
197242
copy:
198-
src: "{{ lookup('env', 'SSL_KEY_PATH') }}"
243+
src: "{{ hostvars[inventory_hostname]['ssl_key_path'] }}"
199244
dest: /etc/mongodb/ssl/mongodb.key
200245
owner: mongodb
201246
group: mongodb
202247
mode: "0400"
203-
remote_src: yes
204248

205-
- name: Copy CA certificate from /var/www/production to MongoDB directory
249+
- name: Copy CA certificate to MongoDB directory
206250
copy:
207-
src: "{{ lookup('env', 'SSL_CA_PATH') }}"
251+
src: "{{ hostvars[inventory_hostname]['ssl_ca_path'] }}"
208252
dest: /etc/mongodb/ssl/ca.pem
209253
owner: mongodb
210254
group: mongodb
211255
mode: "0400"
212-
remote_src: yes
213256

214257
- name: Create MongoDB TLS/SSL certificate PEM file (cert + key)
215258
shell: |
@@ -219,22 +262,6 @@
219262
args:
220263
creates: /etc/mongodb/ssl/mongodb.pem
221264

222-
# Clean up certificates from /var/www/production for security
223-
- name: Remove SSL certificate from /var/www/production (security cleanup)
224-
file:
225-
path: "{{ lookup('env', 'SSL_CERT_PATH') }}"
226-
state: absent
227-
228-
- name: Remove SSL private key from /var/www/production (security cleanup)
229-
file:
230-
path: "{{ lookup('env', 'SSL_KEY_PATH') }}"
231-
state: absent
232-
233-
- name: Remove CA certificate from /var/www/production (security cleanup)
234-
file:
235-
path: "{{ lookup('env', 'SSL_CA_PATH') }}"
236-
state: absent
237-
238265
- name: Configure MongoDB TLS/SSL in mongod.conf
239266
blockinfile:
240267
path: /etc/mongod.conf

0 commit comments

Comments
 (0)