From 8bf5ca3ed23333673e875c2da80c5fe659c5b3a9 Mon Sep 17 00:00:00 2001 From: Benjamin Wenzel Date: Mon, 28 Jun 2021 13:42:09 +0200 Subject: [PATCH] Handle case of absent instance_config.yml gracefully i.e., instead of throwing a red fatal error message at the user and recovering with a rescue block we downgrade the lookup error to a warning and set the same defaults in that case that were set in the rescue block before. See https://github.com/ansible-community/molecule-hetznercloud/issues/31. --- molecule_hetznercloud/playbooks/destroy.yml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/molecule_hetznercloud/playbooks/destroy.yml b/molecule_hetznercloud/playbooks/destroy.yml index 967eef0..f37c1d0 100644 --- a/molecule_hetznercloud/playbooks/destroy.yml +++ b/molecule_hetznercloud/playbooks/destroy.yml @@ -6,16 +6,16 @@ no_log: "{{ molecule_no_log }}" tasks: - name: Populate the instance config - block: - - name: Populate instance config from file - set_fact: - instance_conf: "{{ lookup('file', molecule_instance_config) | from_yaml }}" - skip_instances: false - rescue: - - name: Populate instance config when file missing - set_fact: - instance_conf: {} - skip_instances: true + set_fact: + instance_conf: "{{ lookup('file', molecule_instance_config, errors='warn') | from_yaml }}" + skip_instances: false + register: instance_config_lookup + + - name: Populate instance config when file missing + set_fact: + instance_conf: {} + skip_instances: true + when: not instance_config_lookup.ansible_facts.instance_conf - name: Destroy molecule instance(s) hcloud_server: