Improve certificate existence check by removing bashisms

This commit is contained in:
Andreas Motl 2022-01-25 01:38:37 +01:00
parent 95c899b215
commit 9c0d000138

View File

@ -1,7 +1,6 @@
---
- name: Get installed certificates.
shell: |
{{ certbot_script }} certificates | grep "Domains:" | awk '{ gsub(/ Domains: /,""); print }'
command: "{{ certbot_script }} certificates"
changed_when: false
register: letsencrypt_certs
@ -13,4 +12,4 @@
set_fact:
cert_exists: true
when: cert_item.domains | sort | difference(item) == []
with_list: "{{ letsencrypt_certs.stdout_lines }}"
with_list: "{{ letsencrypt_certs.stdout_lines | select('match', '.*Domains:.*') | map('regex_replace', '^.*Domains: (.*)$', '\\1') }}"