From 78fba4a3e74b889ee9ef738b2d88f7f8ac470dc1 Mon Sep 17 00:00:00 2001 From: David Moreau Simard Date: Mon, 22 Feb 2021 16:05:15 -0500 Subject: [PATCH] sanity: prevent import exception for inventory script Adopt the same pattern as the modules by deferring the exception until later. --- plugins/inventory/hcloud.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/plugins/inventory/hcloud.py b/plugins/inventory/hcloud.py index 080327e..c0a3b90 100644 --- a/plugins/inventory/hcloud.py +++ b/plugins/inventory/hcloud.py @@ -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()