Add cloud-init create method

This commit is contained in:
Duologic 2019-03-29 18:24:53 +01:00
parent 00dc226101
commit 0cad084f4c
4 changed files with 37 additions and 0 deletions

View File

@ -36,3 +36,7 @@ certbot_keep_updated: true
# Where to put Certbot when installing from source.
certbot_dir: /opt/certbot
# When certbot_create_method==cloud-init, test certificates will be installed
# that can be used by a server (eg. nginx)
certbot_cloud_init_test_certificates: true

View File

@ -0,0 +1,21 @@
---
- name: Check if certificate already exists.
stat:
path: /etc/letsencrypt/live/{{ cert_item.domains | first | replace('*.', '') }}/cert.pem
register: letsencrypt_cert
- name: Ensure cloud-init directory exists.
file:
path: /var/lib/cloud/scripts/per-instance
state: directory
- name: Ensure cloud-init creates certificates.
template:
src: certbot-init.sh.j2
dest: "/var/lib/cloud/scripts/per-instance/certbot-init-{{ cert_item.domains | first | replace('*.', '') }}.sh"
- name: Ensure test certificates are created.
command: "{{ certbot_create_command }} --test-cert"
when:
- not letsencrypt_cert.stat.exists
- certbot_cloud_init_test_certificates

View File

@ -15,5 +15,13 @@
loop_control:
loop_var: cert_item
- include_tasks: create-cert-cloud-init.yml
with_items: "{{ certbot_certs }}"
when:
- certbot_create_if_missing
- certbot_create_method == 'cloud-init'
loop_control:
loop_var: cert_item
- import_tasks: renew-cron.yml
when: certbot_auto_renew

View File

@ -0,0 +1,4 @@
#!/bin/sh
set -e
{{ certbot_create_command }}