mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-23 13:20:23 -07:00
Add code to flag legacy templating like $foo.{bar} as deprecated in favor of Jinja2 {{ foo.bar }} so we
can remove the legacy system at a later date.
This commit is contained in:
parent
804056a563
commit
b09ef21ec9
13 changed files with 102 additions and 61 deletions
|
@ -18,6 +18,7 @@
|
|||
import ansible.inventory
|
||||
import ansible.runner
|
||||
import ansible.constants as C
|
||||
from ansible.utils import template
|
||||
from ansible import utils
|
||||
from ansible import errors
|
||||
import ansible.callbacks
|
||||
|
@ -174,9 +175,9 @@ class PlayBook(object):
|
|||
for t in tokens[1:]:
|
||||
|
||||
(k,v) = t.split("=", 1)
|
||||
incvars[k] = utils.template(basedir, v, incvars)
|
||||
incvars[k] = template.template(basedir, v, incvars)
|
||||
|
||||
included_path = utils.path_dwim(basedir, utils.template(basedir, tokens[0], incvars))
|
||||
included_path = utils.path_dwim(basedir, template.template(basedir, tokens[0], incvars))
|
||||
(plays, basedirs) = self._load_playbook_from_file(included_path, incvars)
|
||||
for p in plays:
|
||||
# support for parameterized play includes works by passing
|
||||
|
@ -319,7 +320,7 @@ class PlayBook(object):
|
|||
self.callbacks.task = task
|
||||
self.runner_callbacks.task = task
|
||||
|
||||
self.callbacks.on_task_start(utils.template(play.basedir, task.name, task.module_vars, lookup_fatal=False), is_handler)
|
||||
self.callbacks.on_task_start(template.template(play.basedir, task.name, task.module_vars, lookup_fatal=False), is_handler)
|
||||
if hasattr(self.callbacks, 'skip_task') and self.callbacks.skip_task:
|
||||
return True
|
||||
|
||||
|
@ -354,7 +355,7 @@ class PlayBook(object):
|
|||
for host, results in results.get('contacted',{}).iteritems():
|
||||
if results.get('changed', False):
|
||||
for handler_name in task.notify:
|
||||
self._flag_handler(play, utils.template(play.basedir, handler_name, task.module_vars), host)
|
||||
self._flag_handler(play, template.template(play.basedir, handler_name, task.module_vars), host)
|
||||
|
||||
return hosts_remaining
|
||||
|
||||
|
@ -369,7 +370,7 @@ class PlayBook(object):
|
|||
|
||||
found = False
|
||||
for x in play.handlers():
|
||||
if handler_name == utils.template(play.basedir, x.name, x.module_vars):
|
||||
if handler_name == template.template(play.basedir, x.name, x.module_vars):
|
||||
found = True
|
||||
self.callbacks.on_notify(host, x.name)
|
||||
x.notified_by.append(host)
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
#############################################
|
||||
|
||||
from ansible.utils import template
|
||||
from ansible import utils
|
||||
from ansible import errors
|
||||
from ansible.playbook.task import Task
|
||||
|
@ -64,7 +65,7 @@ class Play(object):
|
|||
|
||||
self._update_vars_files_for_host(None)
|
||||
|
||||
self._ds = ds = utils.template(basedir, ds, self.vars)
|
||||
self._ds = ds = template.template(basedir, ds, self.vars)
|
||||
|
||||
hosts = ds.get('hosts')
|
||||
if hosts is None:
|
||||
|
@ -202,7 +203,7 @@ class Play(object):
|
|||
plugin_name = k[5:]
|
||||
if plugin_name not in utils.plugins.lookup_loader:
|
||||
raise errors.AnsibleError("cannot find lookup plugin named %s for usage in with_%s" % (plugin_name, plugin_name))
|
||||
terms = utils.template(self.basedir, x[k], task_vars)
|
||||
terms = template.template(self.basedir, x[k], task_vars)
|
||||
items = utils.plugins.lookup_loader.get(plugin_name, basedir=self.basedir, runner=None).run(terms, inject=task_vars)
|
||||
elif k.startswith("when_"):
|
||||
included_additional_conditions.append(utils.compile_when_to_only_if("%s %s" % (k[5:], x[k])))
|
||||
|
@ -223,11 +224,11 @@ class Play(object):
|
|||
mv['item'] = item
|
||||
for t in tokens[1:]:
|
||||
(k,v) = t.split("=", 1)
|
||||
mv[k] = utils.template(self.basedir, v, mv)
|
||||
mv[k] = template.template(self.basedir, v, mv)
|
||||
dirname = self.basedir
|
||||
if original_file:
|
||||
dirname = os.path.dirname(original_file)
|
||||
include_file = utils.template(dirname, tokens[0], mv)
|
||||
include_file = template.template(dirname, tokens[0], mv)
|
||||
include_filename = utils.path_dwim(dirname, include_file)
|
||||
data = utils.parse_yaml_from_file(include_filename)
|
||||
results += self._load_tasks(data, mv, included_additional_conditions, original_file=include_filename)
|
||||
|
@ -369,10 +370,10 @@ class Play(object):
|
|||
found = False
|
||||
sequence = []
|
||||
for real_filename in filename:
|
||||
filename2 = utils.template(self.basedir, real_filename, self.vars)
|
||||
filename2 = template.template(self.basedir, real_filename, self.vars)
|
||||
filename3 = filename2
|
||||
if host is not None:
|
||||
filename3 = utils.template(self.basedir, filename2, inject)
|
||||
filename3 = template.template(self.basedir, filename2, inject)
|
||||
filename4 = utils.path_dwim(self.basedir, filename3)
|
||||
sequence.append(filename4)
|
||||
if os.path.exists(filename4):
|
||||
|
@ -402,10 +403,10 @@ class Play(object):
|
|||
else:
|
||||
# just one filename supplied, load it!
|
||||
|
||||
filename2 = utils.template(self.basedir, filename, self.vars)
|
||||
filename2 = template.template(self.basedir, filename, self.vars)
|
||||
filename3 = filename2
|
||||
if host is not None:
|
||||
filename3 = utils.template(self.basedir, filename2, inject)
|
||||
filename3 = template.template(self.basedir, filename2, inject)
|
||||
filename4 = utils.path_dwim(self.basedir, filename3)
|
||||
if self._has_vars_in(filename4):
|
||||
continue
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue