Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create certbot_expand flag that expands certificates if domains changes #223

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ certbot_auto_renew_hour: "3"
certbot_auto_renew_minute: "30"
certbot_auto_renew_options: "--quiet"

certbot_expand: false
certbot_testmode: false
certbot_hsts: false

Expand Down Expand Up @@ -37,6 +38,7 @@ certbot_create_command: >-
{{ cert_item.webroot | default(certbot_webroot) if certbot_create_method == 'webroot' else '' }}
{{ certbot_create_extra_args }}
-d {{ cert_item.domains | join(',') }}
{{ '--expand' if certbot_expand else '' }}
{{ '--pre-hook /etc/letsencrypt/renewal-hooks/pre/stop_services'
if certbot_create_standalone_stop_services and certbot_create_method == 'standalone'
else '' }}
Expand Down
15 changes: 15 additions & 0 deletions tasks/create-cert-standalone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,18 @@
- name: Generate new certificate if one doesn't exist.
command: "{{ certbot_create_command }}"
when: not letsencrypt_cert.stat.exists

- name: Register certificate domains (if certbot_expand)
shell: "{{ certbot_script }} certificates --cert-name {{ cert_item.domains | first | replace('*.', '') }} | grep Domains | cut -d':' -f2"
changed_when: false
register: letsencrypt_cert_domains_dirty
when: certbot_expand and letsencrypt_cert.stat.exists

- name: Cleanup domain list (if certbot_expand)
set_fact:
letsencrypt_cert_domains: "{{ letsencrypt_cert_domains_dirty.stdout | trim | split(' ') | map('trim') | select('!=', '') | list | sort }}"
when: certbot_expand and letsencrypt_cert.stat.exists

- name: Expand certbot certificate (if certbot_expand)
command: "{{ certbot_create_command }}"
when: certbot_expand and letsencrypt_cert.stat.exists and letsencrypt_cert_domains != cert_item.domains | map('trim') | select('!=', '') | list | sort
15 changes: 15 additions & 0 deletions tasks/create-cert-webroot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,18 @@
- name: Generate new certificate if one doesn't exist.
command: "{{ certbot_create_command }}"
when: not letsencrypt_cert.stat.exists

- name: Register certificate domains (if certbot_expand)
shell: "{{ certbot_script }} certificates --cert-name {{ cert_item.domains | first | replace('*.', '') }} | grep Domains | cut -d':' -f2"
changed_when: false
register: letsencrypt_cert_domains_dirty
when: certbot_expand and letsencrypt_cert.stat.exists

- name: Cleanup domain list (if certbot_expand)
set_fact:
letsencrypt_cert_domains: "{{ letsencrypt_cert_domains_dirty.stdout | trim | split(' ') | map('trim') | select('!=', '') | list | sort }}"
when: certbot_expand and letsencrypt_cert.stat.exists

- name: Expand certbot certificate (if certbot_expand)
command: "{{ certbot_create_command }}"
when: certbot_expand and letsencrypt_cert.stat.exists and letsencrypt_cert_domains != cert_item.domains | map('trim') | select('!=', '') | list | sort
Loading