From c0f3a63e1826b793c0955ed65620b2bc9ff3c023 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Sun, 21 Feb 2021 21:11:54 +0100 Subject: [PATCH] Improve infoblox inventory script dependencies. (#1871) --- .../fragments/1871-infoblox-inventory.yml | 2 ++ scripts/inventory/infoblox.py | 18 +++++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 changelogs/fragments/1871-infoblox-inventory.yml diff --git a/changelogs/fragments/1871-infoblox-inventory.yml b/changelogs/fragments/1871-infoblox-inventory.yml new file mode 100644 index 0000000000..d49d176f1b --- /dev/null +++ b/changelogs/fragments/1871-infoblox-inventory.yml @@ -0,0 +1,2 @@ +bugfixes: +- "infoblox inventory script - make sure that the script also works with Ansible 2.9, and returns a more helpful error when community.general is not installed as part of Ansible 2.10/3 (https://github.com/ansible-collections/community.general/pull/1871)." diff --git a/scripts/inventory/infoblox.py b/scripts/inventory/infoblox.py index 9e985a9eb9..209509025e 100644 --- a/scripts/inventory/infoblox.py +++ b/scripts/inventory/infoblox.py @@ -13,10 +13,22 @@ import json import argparse from ansible.parsing.dataloader import DataLoader -from ansible.module_utils.six import iteritems +from ansible.module_utils.six import iteritems, raise_from from ansible.module_utils._text import to_text -from ansible_collections.community.general.plugins.module_utils.net_tools.nios.api import WapiInventory -from ansible_collections.community.general.plugins.module_utils.net_tools.nios.api import normalize_extattrs, flatten_extattrs +try: + from ansible_collections.community.general.plugins.module_utils.net_tools.nios.api import WapiInventory + from ansible_collections.community.general.plugins.module_utils.net_tools.nios.api import normalize_extattrs, flatten_extattrs +except ImportError as exc: + try: + # Fallback for Ansible 2.9 + from ansible.module_utils.net_tools.nios.api import WapiInventory + from ansible.module_utils.net_tools.nios.api import normalize_extattrs, flatten_extattrs + except ImportError: + raise_from( + Exception( + 'This inventory plugin only works with Ansible 2.9, 2.10, or 3, or when community.general is installed correctly in PYTHONPATH.' + ' Try using the inventory plugin from infoblox.nios_modules instead.'), + exc) CONFIG_FILES = [