Add a test for domain list change using grep

pull/50/head
Yoan Tournade 7 years ago
parent 3f1a802d71
commit fa59772ab1
No known key found for this signature in database
GPG Key ID: C6A3FAA68AE36EB4
  1. 18
      tasks/create-cert-standalone.yml
  2. 21
      tasks/test-cert-exists.yml

@ -1,23 +1,27 @@
--- ---
- name: Check if certificate already exists. - name: Check if certificate exists or has been changed
stat: import_tasks: test-cert-exists.yml
path: /etc/letsencrypt/live/{{ cert_item.domains | first }}/cert.pem
register: letsencrypt_cert
- 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_exists.stat.exists
with_items: "{{ certbot_create_standalone_stop_services }}" with_items: "{{ certbot_create_standalone_stop_services }}"
- name: Generate new certificate if one doesn't exist. - name: Generate new certificate if one doesn't exist.
shell: "{{ certbot_create_command }}" shell: "{{ certbot_create_command }}"
when: not letsencrypt_cert.stat.exists when: not letsencrypt_cert_exists.stat.exists
- name: Persist domain list to host
copy:
content: "{{ cert_item.domains }}"
dest: /etc/letsencrypt/domains-{{ cert_item.domains | first }}
when: letsencrypt_cert_updated.rc != 0
- name: Start services after cert has been generated. - name: Start services after cert has been generated.
service: service:
name: "{{ item }}" name: "{{ item }}"
state: started state: started
when: not letsencrypt_cert.stat.exists when: not letsencrypt_cert_exists.stat.exists
with_items: "{{ certbot_create_standalone_stop_services }}" with_items: "{{ certbot_create_standalone_stop_services }}"

@ -0,0 +1,21 @@
---
- name: Check if certificate already exists.
stat:
path: /etc/letsencrypt/live/{{ cert_item.domains | first }}/cert.pem
register: letsencrypt_cert_exists
- name: Check if certificate has changed.
command: grep -Fxq "{{ cert_item.domains }}" /etc/letsencrypt/domains-{{ cert_item.domains | first }}
register: letsencrypt_cert_updated
check_mode: no
ignore_errors: yes
changed_when: no
when: letsencrypt_cert_exists.stat.exists
- debug:
msg: Not changed
when: letsencrypt_cert_updated.rc == 0
- debug:
msg: Changed
when: letsencrypt_cert_updated.rc != 0
Loading…
Cancel
Save