ansible-role-certbot/tasks/create-cert-standalone.yml
nierdz 1411e392be Use more specific services to stop/start during cert creation process
This is useful when you need to stop different services depending
on the certificates. For example, if you have a first certificate
that uses varnish and a second one using nginx you can have a
configuration that looks like this:

certbot_certs:
  - email: janedoe@example.com
    stop_services:
      - varnish
    domains:
      - example1.com
  - email: janedoe@example.com
    stop_services:
      - nginx
    domains:
      - example2.com

This way, you don't have to stop both varnish and nginx during cert
creation process.
2020-12-27 13:15:26 +01:00

24 lines
815 B
YAML

---
- name: Check if certificate already exists.
stat:
path: /etc/letsencrypt/live/{{ cert_item.domains | first | replace('*.', '') }}/cert.pem
register: letsencrypt_cert
- name: Stop services to allow certbot to generate a cert.
service:
name: "{{ item }}"
state: stopped
when: not letsencrypt_cert.stat.exists
with_items: "{{ cert_item.stop_services | default(certbot_create_standalone_stop_services) }}"
- name: Generate new certificate if one doesn't exist.
command: "{{ certbot_create_command }}"
when: not letsencrypt_cert.stat.exists
- name: Start services after cert has been generated.
service:
name: "{{ item }}"
state: started
when: not letsencrypt_cert.stat.exists
with_items: "{{ cert_item.stop_services | default(certbot_create_standalone_stop_services) }}"