mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
bad/missing fact plugin is a warning (#19350)
This commit is contained in:
parent
739a310382
commit
f550b4541f
2 changed files with 12 additions and 11 deletions
13
lib/ansible/plugins/cache/__init__.py
vendored
13
lib/ansible/plugins/cache/__init__.py
vendored
|
@ -33,24 +33,17 @@ except ImportError:
|
||||||
class FactCache(MutableMapping):
|
class FactCache(MutableMapping):
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
|
|
||||||
self._plugin = cache_loader.get(C.CACHE_PLUGIN)
|
self._plugin = cache_loader.get(C.CACHE_PLUGIN)
|
||||||
if not self._plugin:
|
if not self._plugin:
|
||||||
raise AnsibleError('Unable to load the facts cache plugin (%s)\n'
|
raise AnsibleError('Unable to load the facts cache plugin (%s).' % (C.CACHE_PLUGIN))
|
||||||
'Check fact cache config options :\n'
|
|
||||||
'Current values:\n'
|
|
||||||
' fact_caching: %s\n'
|
|
||||||
' fact_caching_connection: %s' %
|
|
||||||
(C.CACHE_PLUGIN, C.CACHE_PLUGIN, C.CACHE_PLUGIN_CONNECTION))
|
|
||||||
|
|
||||||
# Backwards compat: self._display isn't really needed, just import the global display and use that.
|
# Backwards compat: self._display isn't really needed, just import the global display and use that.
|
||||||
self._display = display
|
self._display = display
|
||||||
|
|
||||||
if self._plugin is None:
|
|
||||||
display.warning("Failed to load fact cache plugins")
|
|
||||||
return
|
|
||||||
|
|
||||||
def __getitem__(self, key):
|
def __getitem__(self, key):
|
||||||
if key not in self:
|
if not self._plugin.contains(key):
|
||||||
raise KeyError
|
raise KeyError
|
||||||
return self._plugin.get(key)
|
return self._plugin.get(key)
|
||||||
|
|
||||||
|
|
|
@ -43,6 +43,7 @@ from ansible.template import Templar
|
||||||
from ansible.utils.listify import listify_lookup_plugin_terms
|
from ansible.utils.listify import listify_lookup_plugin_terms
|
||||||
from ansible.utils.vars import combine_vars
|
from ansible.utils.vars import combine_vars
|
||||||
from ansible.vars.unsafe_proxy import wrap_var
|
from ansible.vars.unsafe_proxy import wrap_var
|
||||||
|
from ansible.module_utils._text import to_native
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from __main__ import display
|
from __main__ import display
|
||||||
|
@ -95,7 +96,6 @@ class VariableManager:
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
||||||
self._fact_cache = FactCache()
|
|
||||||
self._nonpersistent_fact_cache = defaultdict(dict)
|
self._nonpersistent_fact_cache = defaultdict(dict)
|
||||||
self._vars_cache = defaultdict(dict)
|
self._vars_cache = defaultdict(dict)
|
||||||
self._extra_vars = defaultdict(dict)
|
self._extra_vars = defaultdict(dict)
|
||||||
|
@ -106,6 +106,14 @@ class VariableManager:
|
||||||
self._omit_token = '__omit_place_holder__%s' % sha1(os.urandom(64)).hexdigest()
|
self._omit_token = '__omit_place_holder__%s' % sha1(os.urandom(64)).hexdigest()
|
||||||
self._options_vars = defaultdict(dict)
|
self._options_vars = defaultdict(dict)
|
||||||
|
|
||||||
|
# bad cache plugin is not fatal error
|
||||||
|
try:
|
||||||
|
self._fact_cache = FactCache()
|
||||||
|
except AnsibleError as e:
|
||||||
|
display.warning(to_native(e))
|
||||||
|
# fallback to a dict as in memory cache
|
||||||
|
self._fact_cache = {}
|
||||||
|
|
||||||
def __getstate__(self):
|
def __getstate__(self):
|
||||||
data = dict(
|
data = dict(
|
||||||
fact_cache = self._fact_cache,
|
fact_cache = self._fact_cache,
|
||||||
|
|
Loading…
Reference in a new issue