bad/missing fact plugin is a warning (#19350)

pull/19364/head
Brian Coca 8 years ago committed by GitHub
parent 739a310382
commit f550b4541f

@ -33,24 +33,17 @@ except ImportError:
class FactCache(MutableMapping):
def __init__(self, *args, **kwargs):
self._plugin = cache_loader.get(C.CACHE_PLUGIN)
if not self._plugin:
raise AnsibleError('Unable to load the facts cache plugin (%s)\n'
'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))
raise AnsibleError('Unable to load the facts cache plugin (%s).' % (C.CACHE_PLUGIN))
# Backwards compat: self._display isn't really needed, just import the global display and use that.
self._display = display
if self._plugin is None:
display.warning("Failed to load fact cache plugins")
return
def __getitem__(self, key):
if key not in self:
if not self._plugin.contains(key):
raise KeyError
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.vars import combine_vars
from ansible.vars.unsafe_proxy import wrap_var
from ansible.module_utils._text import to_native
try:
from __main__ import display
@ -95,7 +96,6 @@ class VariableManager:
def __init__(self):
self._fact_cache = FactCache()
self._nonpersistent_fact_cache = defaultdict(dict)
self._vars_cache = 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._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):
data = dict(
fact_cache = self._fact_cache,

Loading…
Cancel
Save