Use lineinfile to check domain list content

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

@ -14,10 +14,11 @@
when: not letsencrypt_cert_exists.stat.exists when: not letsencrypt_cert_exists.stat.exists
- name: Persist domain list to host - name: Persist domain list to host
copy: lineinfile:
content: "{{ cert_item.domains }}" path: /etc/letsencrypt/domains-{{ cert_item.domains | first }}
dest: /etc/letsencrypt/domains-{{ cert_item.domains | first }} line: "{{ cert_item.domains }}"
when: letsencrypt_cert_updated.rc != 0 state: present
when: letsencrypt_cert_updated
- name: Start services after cert has been generated. - name: Start services after cert has been generated.
service: service:

@ -5,17 +5,14 @@
register: letsencrypt_cert_exists register: letsencrypt_cert_exists
- name: Check if certificate has changed. - name: Check if certificate has changed.
command: grep -Fxq "{{ cert_item.domains }}" /etc/letsencrypt/domains-{{ cert_item.domains | first }} lineinfile:
register: letsencrypt_cert_updated path: /etc/letsencrypt/domains-{{ cert_item.domains | first }}
check_mode: no line: "{{ cert_item.domains }}"
ignore_errors: yes state: present
changed_when: no check_mode: yes
register: letsencrypt_cert_contents
when: letsencrypt_cert_exists.stat.exists when: letsencrypt_cert_exists.stat.exists
- debug: - set_fact:
msg: Not changed letsencrypt_cert_updated: "{{ (letsencrypt_cert_contents | changed) or (letsencrypt_cert_contents | failed) }}"
when: letsencrypt_cert_updated.rc == 0 when: letsencrypt_cert_exists.stat.exists
- debug:
msg: Changed
when: letsencrypt_cert_updated.rc != 0

Loading…
Cancel
Save