mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-23 05:10:22 -07:00
Add new level of vars to deal with set_fact/register precedence rules
This commit is contained in:
parent
926f127245
commit
56d7f3889d
2 changed files with 15 additions and 13 deletions
|
@ -238,11 +238,12 @@ class StrategyBase:
|
||||||
|
|
||||||
elif result[0] == 'register_host_var':
|
elif result[0] == 'register_host_var':
|
||||||
# essentially the same as 'set_host_var' below, however we
|
# essentially the same as 'set_host_var' below, however we
|
||||||
# never follow the delegate_to value for registered vars
|
# never follow the delegate_to value for registered vars and
|
||||||
|
# the variable goes in the fact_cache
|
||||||
host = result[1]
|
host = result[1]
|
||||||
var_name = result[2]
|
var_name = result[2]
|
||||||
var_value = result[3]
|
var_value = result[3]
|
||||||
self._variable_manager.set_host_variable(host, var_name, var_value)
|
self._variable_manager.set_host_facts(host, {var_name: var_value})
|
||||||
|
|
||||||
elif result[0] in ('set_host_var', 'set_host_facts'):
|
elif result[0] in ('set_host_var', 'set_host_facts'):
|
||||||
host = result[1]
|
host = result[1]
|
||||||
|
|
|
@ -48,14 +48,14 @@ class VariableManager:
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
||||||
self._fact_cache = FactCache()
|
self._fact_cache = FactCache()
|
||||||
self._vars_cache = defaultdict(dict)
|
self._nonpersistent_fact_cache = defaultdict(dict)
|
||||||
self._extra_vars = defaultdict(dict)
|
self._vars_cache = defaultdict(dict)
|
||||||
self._host_vars_files = defaultdict(dict)
|
self._extra_vars = defaultdict(dict)
|
||||||
|
self._host_vars_files = defaultdict(dict)
|
||||||
self._group_vars_files = defaultdict(dict)
|
self._group_vars_files = defaultdict(dict)
|
||||||
self._inventory = None
|
self._inventory = None
|
||||||
|
self._omit_token = '__omit_place_holder__%s' % sha1(os.urandom(64)).hexdigest()
|
||||||
self._omit_token = '__omit_place_holder__%s' % sha1(os.urandom(64)).hexdigest()
|
|
||||||
|
|
||||||
def _get_cache_entry(self, play=None, host=None, task=None):
|
def _get_cache_entry(self, play=None, host=None, task=None):
|
||||||
play_id = "NONE"
|
play_id = "NONE"
|
||||||
|
@ -179,13 +179,14 @@ class VariableManager:
|
||||||
for item in data:
|
for item in data:
|
||||||
all_vars = combine_vars(all_vars, item)
|
all_vars = combine_vars(all_vars, item)
|
||||||
|
|
||||||
# finally, the facts cache for this host, if it exists
|
# finally, the facts caches for this host, if it exists
|
||||||
try:
|
try:
|
||||||
host_facts = self._fact_cache.get(host.name, dict())
|
host_facts = self._fact_cache.get(host.name, dict())
|
||||||
for k in host_facts.keys():
|
for k in host_facts.keys():
|
||||||
if host_facts[k] is not None and not isinstance(host_facts[k], UnsafeProxy):
|
if host_facts[k] is not None and not isinstance(host_facts[k], UnsafeProxy):
|
||||||
host_facts[k] = UnsafeProxy(host_facts[k])
|
host_facts[k] = UnsafeProxy(host_facts[k])
|
||||||
all_vars = combine_vars(all_vars, host_facts)
|
all_vars = combine_vars(all_vars, host_facts)
|
||||||
|
all_vars = combine_vars(all_vars, self._nonpersistent_fact_cache.get(host.name, dict()))
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -370,12 +371,12 @@ class VariableManager:
|
||||||
assert isinstance(facts, dict)
|
assert isinstance(facts, dict)
|
||||||
|
|
||||||
if host.name not in self._fact_cache:
|
if host.name not in self._fact_cache:
|
||||||
self._fact_cache[host.name] = facts
|
self._nonpersistent_fact_cache[host.name] = facts
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
self._fact_cache[host.name].update(facts)
|
self._nonpersistent_fact_cache[host.name].update(facts)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
self._fact_cache[host.name] = facts
|
self._nonpersistent_fact_cache[host.name] = facts
|
||||||
|
|
||||||
def set_host_variable(self, host, varname, value):
|
def set_host_variable(self, host, varname, value):
|
||||||
'''
|
'''
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue