Skip to content

Commit c7b94e1

Browse files
Update planet to work with local letsencrypt (#260)
* Update planet to work with local letsencrypt * Update salt/planet/init.sls Co-authored-by: Ee Durbin <[email protected]> * Update salt/planet/init.sls Co-authored-by: Ee Durbin <[email protected]> * Update salt/planet/init.sls Co-authored-by: Ee Durbin <[email protected]>
1 parent f877ca8 commit c7b94e1

File tree

4 files changed

+38
-13
lines changed

4 files changed

+38
-13
lines changed

pillar/base/planet.sls

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
planet_sites:
2-
planetpython.org:
3-
config: config.ini
4-
extra_domains:
5-
- www.planetpython.org
6-
# planet.jython.org:
7-
# config: jython.ini
1+
planet:
2+
subject_alternative_names:
3+
- planetpython.org
4+
- www.planetpython.org
5+
sites:
6+
planetpython.org:
7+
config: config.ini

salt/planet/config/nginx.planet.conf.jinja

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{% for site, info in salt["pillar.get"]("planet_sites").items() %}
1+
{% for site, info in salt["pillar.get"]("planet", {}).get("sites").items() %}
22

33
server {
44
listen 80;
@@ -11,13 +11,13 @@ server {
1111
server_name {{ site }};
1212
error_log /var/log/nginx/{{ site }}.error.log;
1313
access_log /var/log/nginx/{{ site }}.access.log;
14-
ssl_certificate /etc/letsencrypt/live/{{ site }}/fullchain.pem;
15-
ssl_certificate_key /etc/letsencrypt/live/{{ site }}/privkey.pem;
14+
ssl_certificate /etc/lego/certificates/{{ grains['fqdn'] }}.crt;
15+
ssl_certificate_key /etc/lego/certificates/{{ grains['fqdn'] }}.key;
1616

1717
root /srv/{{ site }}/;
1818
}
1919

20-
{% for domain in info.get("extra_domains", []) %}
20+
{% for domain in info.get("subject_alternative_names", []) %}
2121
server {
2222
server_name {{ domain }};
2323
error_log /var/log/nginx/redir-{{ domain }}.error.log;
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
cd /srv/planet/
22
git pull
3-
{% for site in salt["pillar.get"]("planet_sites").values() %}
3+
{% for site in salt["pillar.get"]("planet", {}).get("sites").values() %}
44
$(which python2.7) /srv/planet/code/planet.py /srv/planet/config/{{ site["config"] }}
55
{% endfor %}

salt/planet/init.sls

+26-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
include:
22
- nginx
3+
- tls.lego
34

45
git:
56
pkg.installed
@@ -19,6 +20,30 @@ planet-user:
1920
- require:
2021
- file: /etc/nginx/sites.d/
2122

23+
lego_bootstrap:
24+
cmd.run:
25+
- name: /usr/local/bin/lego -a --email="[email protected]" {% if pillar["dc"] == "vagrant" %}--server=https://salt-master.vagrant.psf.io:14000/dir{% endif %} --domains="{{ grains['fqdn'] }}" {%- for domain in pillar['planet']['subject_alternative_names'] %} --domains {{ domain }}{%- endfor %} --http --path /etc/lego --key-type ec256 run
26+
- creates: /etc/lego/certificates/{{ grains['fqdn'] }}.json
27+
28+
lego_renew:
29+
cron.present:
30+
- name: /usr/local/bin/lego -a --email="[email protected]" {% if pillar["dc"] == "vagrant" %}--server=https://salt-master.vagrant.psf.io:14000/dir{% endif %} --domains="{{ grains['fqdn'] }}" {%- for domain in pillar['planet']['subject_alternative_names'] %} --domains {{ domain }}{%- endfor %} --http --http.webroot /etc/lego --path /etc/lego --key-type ec256 renew --days 30 && /usr/sbin/service nginx reload
31+
- identifier: roundup_lego_renew
32+
- hour: 0
33+
- minute: random
34+
35+
lego_config:
36+
file.managed:
37+
- name: /etc/nginx/conf.d/lego.conf
38+
- source: salt://tls/config/lego.conf.jinja
39+
- template: jinja
40+
- user: root
41+
- group: root
42+
- mode: 644
43+
- require:
44+
- sls: tls.lego
45+
- cmd: lego_bootstrap
46+
2247
/srv/planet/:
2348
file.directory:
2449
- user: planet
@@ -53,7 +78,7 @@ https://github.com/python/planet:
5378
- minute: 37
5479
- hour: 1,4,7,10,13,16,19,21
5580
56-
{% for site in salt["pillar.get"]("planet_sites") %}
81+
{% for site in salt["pillar.get"]("planet", {}).get("sites", []) %}
5782
/srv/{{ site }}/:
5883
file.directory:
5984
- user: planet

0 commit comments

Comments
 (0)