ansible-community / molecule-hetznercloud

A molecule driver for Hetzner Cloud
https://ansible.readthedocs.io/projects/molecule/
GNU Lesser General Public License v3.0
27 stars 14 forks source link

Handle case of absent instance_config.yml gracefully #32

Closed tumbl3w33d closed 3 years ago

tumbl3w33d commented 3 years ago

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.

happy path:

PLAY [Destroy] *****************************************************************

TASK [Populate the instance config] ********************************************
ok: [localhost]

TASK [Populate instance config when file missing] ******************************
skipping: [localhost]

failed lookup case (the debug statements were just added to demonstrate the change of facts):

PLAY [Destroy] *****************************************************************

TASK [Populate the instance config] ********************************************
[WARNING]: Unable to find 'foo.yml' in expected paths (use -vvvvv to see paths)
[WARNING]: An unhandled exception occurred while running the lookup plugin
'file'. Error was a <class 'ansible.errors.AnsibleError'>, original message:
could not locate file in lookup: foo.yml
ok: [localhost]

TASK [debug] *******************************************************************
ok: [localhost] => {
    "instance_conf": ""
}

TASK [debug] *******************************************************************
ok: [localhost] => {
    "skip_instances": false
}

TASK [Populate instance config when file missing] ******************************
ok: [localhost]

TASK [debug] *******************************************************************
ok: [localhost] => {
    "instance_conf": {}
}

TASK [debug] *******************************************************************
ok: [localhost] => {
    "skip_instances": true
}

This fixes one aspect of #31 .

decentral1se commented 3 years ago

Merged in https://git.autonomic.zone/autonomic-cooperative/molecule-hetznercloud/pulls/13 :rocket:

Thanks!!!

If you manage to resolve #31 (or whoever gets there), I will make a new release ASAP then after.