Commit c3d4c492 authored by Mattia Rizzolo's avatar Mattia Rizzolo

deploy ssl-keys after a bunch of random fixups

* use run-parts to run the hooks, instead of embedding everything in
  dehydrated's hook scripts
* add the local hostname to the "domains" file
* no support for ssl cert request through ansible yet
Signed-off-by: Mattia Rizzolo's avatarMattia Rizzolo <mattia@debian.org>
parent d1c73c2b
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
- mattia - mattia
- pietro - pietro
# - role: ssl-keys - role: ssl-keys
- role: nginx - role: nginx
proxy: proxy:
......
...@@ -12,11 +12,8 @@ ...@@ -12,11 +12,8 @@
- name: Request an SSL certificate for the domains - name: Request an SSL certificate for the domains
lineinfile: lineinfile:
path: /usr/local/share/ssl-keys/domains path: "{{ ssl_home }}/domains"
line: "{{ item }}" line: "{{ item }}"
state: present state: present
with_items: "{{ proxy.keys() }}" with_items: "{{ proxy.keys() }}"
notify:
- ssl-keys.request
...@@ -43,9 +43,9 @@ ...@@ -43,9 +43,9 @@
- name: Add an hook to reload nginx when there are new ssl keys - name: Add an hook to reload nginx when there are new ssl keys
template: template:
src: reload-nginx.sh src: reload-nginx
dest: "{{ ssl_home }}/hooks" dest: "{{ ssl_home }}/hooks"
mode: 0755 mode: 0755
owner: root owner: root
group: ssl-keys group: ssl-cert
--- ---
- apt:
name: ssl-cert
- name: Create the ssl-keys user - name: Create the ssl-keys user
user: user:
name: ssl-keys name: ssl-keys
...@@ -17,7 +20,7 @@ ...@@ -17,7 +20,7 @@
state: directory state: directory
mode: 0755 mode: 0755
owner: root owner: root
group: ssl-cert group: root
- name: Create the ssl_home/hooks directory - name: Create the ssl_home/hooks directory
file: file:
...@@ -25,7 +28,7 @@ ...@@ -25,7 +28,7 @@
state: directory state: directory
mode: 0755 mode: 0755
owner: root owner: root
group: ssl-keys group: ssl-cert
- name: Create the ssl_home/localcerts directory - name: Create the ssl_home/localcerts directory
file: file:
...@@ -35,12 +38,15 @@ ...@@ -35,12 +38,15 @@
owner: ssl-keys owner: ssl-keys
group: ssl-cert group: ssl-cert
- name: Ensure the ssl_home/domains file exists - name: Create the ssl_home/domains file, with the local hostname in it
file: lineinfile:
dest: "{{ ssl_home }}/domains" path: "{{ ssl_home }}/domains"
force: no create: yes
owner: root owner: root
group: ssl-cert group: ssl-cert
mode: 0644
insertbefore: BOF
line: "{{ inventory_hostname }}"
- name: configure sudo so cron can renew certs by itself - name: configure sudo so cron can renew certs by itself
template: template:
......
...@@ -52,7 +52,7 @@ ...@@ -52,7 +52,7 @@
- name: Create the acme-challenges directory - name: Create the acme-challenges directory
file: path=/var/lib/dehydrated/acme-challenges file: path=/var/lib/dehydrated/acme-challenges
owner=ssl-keys owner=ssl-keys
group=ssl-keys group=ssl-cert
mode=0755 mode=0755
state=directory state=directory
......
--- ---
- set_fact:
ssl_home: "{{ ssl_home }}"
- include_tasks: common.yml - include_tasks: common.yml
- include_tasks: self-signed.yml - include_tasks: self-signed.yml
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
PRIVATE_KEY_RENEW="no" PRIVATE_KEY_RENEW="no"
HOOK="/etc/dehydrated/hook.sh" HOOK="/etc/dehydrated/hook.sh"
CONTACT_EMAIL=" {{ letsencrypt_email }}" CONTACT_EMAIL="{{ letsencrypt_email }}"
DOMAINS_TXT = "{{ ssl_home }}/domains" DOMAINS_TXT = "{{ ssl_home }}/domains"
CERTDIR = "{{ ssl_home }}/localcerts" CERTDIR = "{{ ssl_home }}/localcerts"
...@@ -10,37 +10,10 @@ _log () { ...@@ -10,37 +10,10 @@ _log () {
echo " + ($OP) $*" echo " + ($OP) $*"
} }
reload_apache () {
_log "Reloading apache..."
sudo apache2ctl graceful
# the next cert challenge verification would timeout if attempted right after
# not sure what's wrong with it (I observe this behaviour only on magog), so
# let's just sleep a bit for now
sleep 10
}
reload_nginx () {
_log "Reloading nginx..."
sudo service nginx reload
}
reload_postfix () {
_log "Reloading postfix..."
sudo service postfix reload
}
case "$OP" in case "$OP" in
deploy_cert) deploy_cert)
DOMAIN="$1" DOMAIN="$1"
{% if local_webserver == 'nginx' %} run-parts --exit-on-error --arg="$DOMAIN" --report -- {{ ssl_home }}/hooks
reload_ngnix
{% elif local_webserver == 'apache' %}
reload_apache
{% endif %}
if [ "${DOMAIN}" = "$(hostname -f)" ]; then
reload_postfix
fi
;; ;;
*) *)
;; ;;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment