1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Fix the linode inventory plugin, and the redis and memcached cache plugins (#1281, #1282, #1283).

This commit is contained in:
Felix Fontein 2020-11-13 21:34:56 +01:00 committed by David Moreau Simard
parent 07fa7ea409
commit 75fd32ca55
4 changed files with 19 additions and 3 deletions

View file

@ -0,0 +1,4 @@
bugfixes:
- "linode inventory plugin - make sure that plugin errors out on initialization if the required library is not found, and not on load-time (https://github.com/ansible-collections/community.general/pull/1297)."
- "redis cache plugin - make sure that plugin errors out on initialization if the required library is not found, and not on load-time (https://github.com/ansible-collections/community.general/pull/1297)."
- "memcached cache plugin - make sure that plugin errors out on initialization if the required library is not found, and not on load-time (https://github.com/ansible-collections/community.general/pull/1297)."

View file

@ -57,8 +57,9 @@ from ansible.utils.display import Display
try:
import memcache
HAS_MEMCACHE = True
except ImportError:
raise AnsibleError("python-memcached is required for the memcached fact cache")
HAS_MEMCACHE = False
display = Display()
@ -187,6 +188,9 @@ class CacheModule(BaseCacheModule):
self._timeout = C.CACHE_PLUGIN_TIMEOUT
self._prefix = C.CACHE_PLUGIN_PREFIX
if not HAS_MEMCACHE:
raise AnsibleError("python-memcached is required for the memcached fact cache")
self._cache = {}
self._db = ProxyClientPool(connection, debug=0)
self._keys = CacheModuleKeys(self._db, self._db.get(CacheModuleKeys.PREFIX) or [])

View file

@ -73,8 +73,9 @@ from ansible.utils.display import Display
try:
from redis import StrictRedis, VERSION
HAS_REDIS = True
except ImportError:
raise AnsibleError("The 'redis' python module (version 2.4.5 or newer) is required for the redis fact cache, 'pip install redis'")
HAS_REDIS = False
display = Display()
@ -111,6 +112,9 @@ class CacheModule(BaseCacheModule):
self._prefix = C.CACHE_PLUGIN_PREFIX
self._keys_set = 'ansible_cache_keys'
if not HAS_REDIS:
raise AnsibleError("The 'redis' python module (version 2.4.5 or newer) is required for the redis fact cache, 'pip install redis'")
self._cache = {}
kw = {}

View file

@ -63,8 +63,9 @@ from ansible.plugins.inventory import BaseInventoryPlugin
try:
from linode_api4 import LinodeClient
from linode_api4.errors import ApiError as LinodeApiError
HAS_LINODE = True
except ImportError:
raise AnsibleError('the Linode dynamic inventory plugin requires linode_api4.')
HAS_LINODE = False
class InventoryModule(BaseInventoryPlugin):
@ -194,6 +195,9 @@ class InventoryModule(BaseInventoryPlugin):
"""Dynamically parse Linode the cloud inventory."""
super(InventoryModule, self).parse(inventory, loader, path)
if not HAS_LINODE:
raise AnsibleError('the Linode dynamic inventory plugin requires linode_api4.')
config_data = self._read_config_data(path)
self._build_client()