mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-08 14:22:46 +00:00
Templar: encapsulate _available_variables (#55435)
Ensure variables are reset between iterations
This commit is contained in:
committed by
Brian Coca
parent
bd061fd632
commit
34e9d6781b
@@ -349,7 +349,7 @@ class Constructable(object):
|
||||
def _compose(self, template, variables):
|
||||
''' helper method for plugins to compose variables for Ansible based on jinja2 expression and inventory vars'''
|
||||
t = self.templar
|
||||
t.set_available_variables(variables)
|
||||
t.available_variables = variables
|
||||
return t.template('%s%s%s' % (t.environment.variable_start_string, template, t.environment.variable_end_string), disable_lookups=True)
|
||||
|
||||
def _set_composite_vars(self, compose, variables, host, strict=False):
|
||||
@@ -369,7 +369,7 @@ class Constructable(object):
|
||||
# process each 'group entry'
|
||||
if groups and isinstance(groups, dict):
|
||||
variables = combine_vars(variables, self.inventory.get_host(host).get_vars())
|
||||
self.templar.set_available_variables(variables)
|
||||
self.templar.available_variables = variables
|
||||
for group_name in groups:
|
||||
conditional = "{%% if %s %%} True {%% else %%} False {%% endif %%}" % groups[group_name]
|
||||
group_name = self._sanitize_group_name(group_name)
|
||||
|
||||
@@ -348,7 +348,7 @@ class InventoryModule(BaseInventoryPlugin, Constructable):
|
||||
|
||||
# FUTURE: fix underlying inventory stuff to allow us to quickly access known groupvars from reconciled host
|
||||
def _filter_host(self, inventory_hostname, hostvars):
|
||||
self.templar.set_available_variables(hostvars)
|
||||
self.templar.available_variables = hostvars
|
||||
|
||||
for condition in self._filters:
|
||||
# FUTURE: should warn/fail if conditional doesn't return True or False
|
||||
|
||||
@@ -101,9 +101,8 @@ class InventoryModule(BaseInventoryPlugin):
|
||||
return valid
|
||||
|
||||
def template(self, pattern, variables):
|
||||
t = self.templar
|
||||
t.set_available_variables(variables)
|
||||
return t.do_template(pattern)
|
||||
self.templar.available_variables = variables
|
||||
return self.templar.do_template(pattern)
|
||||
|
||||
def add_parents(self, inventory, child, parents, template_vars):
|
||||
for parent in parents:
|
||||
|
||||
Reference in New Issue
Block a user