- name: Check for certs file: path: "/home/nextcloud/nginx/certs/{{ item }}" state: file loop: - "{{ inventory_hostname }}.key" - "{{ inventory_hostname }}.crt" ignore_errors: true register: iscert - debug: msg="{{ iscert.msg }}" - import_tasks: certificates_self.yml when: "'self' in certificates and 'failed' in iscert.msg" - import_tasks: certificates_certbot.yml when: "'certbot' in certificates and 'failed' in iscert.msg"