Do not try to stop services which don't exist yet

This solves a chicken and egg problem where a certificate needed for a service
to run does not exist yet and certbot role fails on stopping a service which is
not yet installed.
This commit is contained in:
Stanislav German-Evtushenko 2020-01-23 09:36:52 +09:00
parent 6e17af0ac5
commit cc9c24c195

View File

@ -4,12 +4,15 @@
path: /etc/letsencrypt/live/{{ cert_item.domains | first | replace('*.', '') }}/cert.pem path: /etc/letsencrypt/live/{{ cert_item.domains | first | replace('*.', '') }}/cert.pem
register: letsencrypt_cert register: letsencrypt_cert
- name: Populate service facts
service_facts:
- name: Stop services to allow certbot to generate a cert. - name: Stop services to allow certbot to generate a cert.
service: service:
name: "{{ item }}" name: "{{ item }}"
state: stopped state: stopped
when: not letsencrypt_cert.stat.exists when: not letsencrypt_cert.stat.exists
with_items: "{{ certbot_create_standalone_stop_services }}" with_items: "{{ certbot_create_standalone_stop_services | intersect(services) }}"
- 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 }}"
@ -20,4 +23,4 @@
name: "{{ item }}" name: "{{ item }}"
state: started state: started
when: not letsencrypt_cert.stat.exists when: not letsencrypt_cert.stat.exists
with_items: "{{ certbot_create_standalone_stop_services }}" with_items: "{{ certbot_create_standalone_stop_services | intersect(services) }}"