explicitly determine whether the domain list has changed

pull/230/head
Florian R. Hölzlwimmer 2 days ago
commit 2fde934223
  1. 8
      defaults/main.yml
  2. 29
      tasks/create-cert-standalone.yml
  3. 29
      tasks/create-cert-webroot.yml

@ -6,6 +6,7 @@ certbot_auto_renew_hour: "3"
certbot_auto_renew_minute: "30" certbot_auto_renew_minute: "30"
certbot_auto_renew_options: "--quiet" certbot_auto_renew_options: "--quiet"
certbot_expand: true
certbot_testmode: false certbot_testmode: false
certbot_hsts: false certbot_hsts: false
@ -14,13 +15,13 @@ certbot_hsts: false
certbot_create_if_missing: false certbot_create_if_missing: false
certbot_create_method: standalone certbot_create_method: standalone
certbot_admin_email: email@example.com certbot_admin_email: email@example.com
certbot_expand: false
# Default webroot, overwritten by individual per-cert webroot directories # Default webroot, overwritten by individual per-cert webroot directories
certbot_webroot: /var/www/letsencrypt certbot_webroot: /var/www/letsencrypt
certbot_certs: [] certbot_certs: []
# - email: janedoe@example.com # - name: example.com
# email: janedoe@example.com
# webroot: "/var/www/html/" # webroot: "/var/www/html/"
# domains: # domains:
# - example1.com # - example1.com
@ -40,8 +41,9 @@ certbot_create_command: >-
{{ '--webroot-path ' if certbot_create_method == 'webroot' else '' }} {{ '--webroot-path ' if certbot_create_method == 'webroot' else '' }}
{{ cert_item.webroot | default(certbot_webroot) if certbot_create_method == 'webroot' else '' }} {{ cert_item.webroot | default(certbot_webroot) if certbot_create_method == 'webroot' else '' }}
{{ certbot_create_extra_args }} {{ certbot_create_extra_args }}
--cert-name {{ cert_item.name | default(cert_item.domains | first | replace('*.', '') ) }} --cert-name {{ cert_item_name }}
-d {{ cert_item.domains | join(',') }} -d {{ cert_item.domains | join(',') }}
{{ '--expand' if certbot_expand else '' }}
{{ '--pre-hook /etc/letsencrypt/renewal-hooks/pre/stop_services' {{ '--pre-hook /etc/letsencrypt/renewal-hooks/pre/stop_services'
if certbot_create_standalone_stop_services and certbot_create_method == 'standalone' if certbot_create_standalone_stop_services and certbot_create_method == 'standalone'
else '' }} else '' }}

@ -1,4 +1,13 @@
--- ---
- name: Determine certificate name
set_fact:
cert_item_name: "{{ cert_item.name | default(cert_item.domains | first | replace('*.', '')) }}"
- name: Check if certificate already exists.
stat:
path: /etc/letsencrypt/live/{{ cert_item_name }}/cert.pem
register: letsencrypt_cert
- name: Ensure pre and post hook folders exist. - name: Ensure pre and post hook folders exist.
file: file:
path: /etc/letsencrypt/renewal-hooks/{{ item }} path: /etc/letsencrypt/renewal-hooks/{{ item }}
@ -32,7 +41,23 @@
- certbot_create_standalone_stop_services is defined - certbot_create_standalone_stop_services is defined
- certbot_create_standalone_stop_services - certbot_create_standalone_stop_services
- name: Check if domains have changed
block:
- name: Register certificate domains
shell: "{{ certbot_script }} certificates --cert-name {{ cert_item_name }} | grep Domains | cut -d':' -f2"
changed_when: false
register: letsencrypt_cert_domains_dirty
- name: Cleanup domain list
set_fact:
letsencrypt_cert_domains: "{{ letsencrypt_cert_domains_dirty.stdout | trim | split(' ') | map('trim') | select('!=', '') | list | sort }}"
- name: Determine if domains have changed
set_fact:
letsencrypt_cert_domains_changed: "{{ letsencrypt_cert_domains != (cert_item.domains | map('trim') | select('!=', '') | list | sort) }}"
when: letsencrypt_cert.stat.exists
- name: Generate new certificate if one doesn't exist. - name: Generate new certificate if one doesn't exist.
command: "{{ certbot_create_command }}" command: "{{ certbot_create_command }}"
register: certbot_create when: not letsencrypt_cert.stat.exists or letsencrypt_cert_domains_changed | default(false)
changed_when: "'no action taken' not in certbot_create.stdout"

@ -1,10 +1,35 @@
--- ---
- name: Determine certificate name
set_fact:
cert_item_name: "{{ cert_item.name | default(cert_item.domains | first | replace('*.', '')) }}"
- name: Check if certificate already exists.
stat:
path: /etc/letsencrypt/live/{{ cert_item_name }}/cert.pem
register: letsencrypt_cert
- name: Create webroot directory if it doesn't exist yet - name: Create webroot directory if it doesn't exist yet
file: file:
path: "{{ cert_item.webroot | default(certbot_webroot) }}" path: "{{ cert_item.webroot | default(certbot_webroot) }}"
state: directory state: directory
- name: Check if domains have changed
block:
- name: Register certificate domains
shell: "{{ certbot_script }} certificates --cert-name {{ cert_item_name }} | grep Domains | cut -d':' -f2"
changed_when: false
register: letsencrypt_cert_domains_dirty
- name: Cleanup domain list
set_fact:
letsencrypt_cert_domains: "{{ letsencrypt_cert_domains_dirty.stdout | trim | split(' ') | map('trim') | select('!=', '') | list | sort }}"
- name: Determine if domains have changed
set_fact:
letsencrypt_cert_domains_changed: "{{ letsencrypt_cert_domains != (cert_item.domains | map('trim') | select('!=', '') | list | sort) }}"
when: letsencrypt_cert.stat.exists
- name: Generate new certificate if one doesn't exist. - name: Generate new certificate if one doesn't exist.
command: "{{ certbot_create_command }}" command: "{{ certbot_create_command }}"
register: certbot_create when: not letsencrypt_cert.stat.exists or letsencrypt_cert_domains_changed | default(false)
changed_when: "'no action taken' not in certbot_create.stdout"

Loading…
Cancel
Save