From e1d787d811d90904c9fbff6e7cb0ed935cb0014c Mon Sep 17 00:00:00 2001 From: Yoan Tournade Date: Fri, 16 Feb 2018 00:08:49 +0100 Subject: [PATCH] Use lineinfile to check domain list content --- tasks/create-cert-standalone.yml | 9 +++++---- tasks/test-cert-exists.yml | 21 +++++++++------------ 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/tasks/create-cert-standalone.yml b/tasks/create-cert-standalone.yml index 1e813d5..b84204c 100644 --- a/tasks/create-cert-standalone.yml +++ b/tasks/create-cert-standalone.yml @@ -14,10 +14,11 @@ 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 + lineinfile: + path: /etc/letsencrypt/domains-{{ cert_item.domains | first }} + line: "{{ cert_item.domains }}" + state: present + when: letsencrypt_cert_updated - name: Start services after cert has been generated. service: diff --git a/tasks/test-cert-exists.yml b/tasks/test-cert-exists.yml index 518f8b4..eca752e 100644 --- a/tasks/test-cert-exists.yml +++ b/tasks/test-cert-exists.yml @@ -5,17 +5,14 @@ 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 + lineinfile: + path: /etc/letsencrypt/domains-{{ cert_item.domains | first }} + line: "{{ cert_item.domains }}" + state: present + check_mode: yes + register: letsencrypt_cert_contents 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 +- set_fact: + letsencrypt_cert_updated: "{{ (letsencrypt_cert_contents | changed) or (letsencrypt_cert_contents | failed) }}" + when: letsencrypt_cert_exists.stat.exists