1
0
Fork 0
mirror of https://github.com/ansible-collections/hetzner.hcloud.git synced 2026-02-04 08:01:49 +00:00

sanity: prevent import exception for inventory script

Adopt the same pattern as the modules by deferring the exception until
later.
This commit is contained in:
David Moreau Simard 2021-02-22 16:05:15 -05:00
parent 64bdcc3ba3
commit 78fba4a3e7
No known key found for this signature in database
GPG key ID: 7D4729EC4E64E8B7

View file

@ -102,8 +102,9 @@ from ansible.release import __version__
try:
from hcloud import hcloud
from hcloud import APIException
HAS_HCLOUD = True
except ImportError:
raise AnsibleError("The Hetzner Cloud dynamic inventory plugin requires hcloud-python.")
HAS_HCLOUD = False
class InventoryModule(BaseInventoryPlugin, Constructable):
@ -243,6 +244,10 @@ class InventoryModule(BaseInventoryPlugin, Constructable):
def parse(self, inventory, loader, path, cache=True):
super(InventoryModule, self).parse(inventory, loader, path, cache)
if not HAS_HCLOUD:
raise AnsibleError("The Hetzner Cloud dynamic inventory plugin requires hcloud-python.")
self._read_config_data(path)
self._configure_hcloud_client()
self._test_hcloud_token()