Add a warning when using jinja template syntax in arguments.
An old leftover that I missed deprecating for removal in v1, so will
show a warning until removed in v2.
@@ -227,12 +227,18 @@ def log_host_command_error(host, e, timeout=0):
raise e
+@memoize
+def show_get_arg_value_warning():
+ logger.warning((
+ 'Use of jinja2 templating in arguments is deprecated, '
+ 'please use builtin Python string formatting.'
+ ))
+
+
+# TODO: remove this! COMPAT w/<1
def get_arg_value(state, host, arg):
'''
- Runs string arguments through the jinja2 templating system with a state and
- host. Used to avoid string formatting in deploy operations which result in
- one operation per host/variable. By parsing the commands after we generate
- the ``op_hash``, multiple command variations can fall under one op.
+ This functions is **deprecated**.
'''
if isinstance(arg, six.string_types):
@@ -242,9 +248,13 @@ def get_arg_value(state, host, arg):
}
try:
- return get_template(arg, is_string=True).render(data)
+ rendered_arg = get_template(arg, is_string=True).render(data)
except (TemplateSyntaxError, UndefinedError) as e:
raise PyinfraError('Error in template string: {0}'.format(e))
+ else:
+ if rendered_arg != arg:
+ show_get_arg_value_warning()
+ return rendered_arg
elif isinstance(arg, list):
return [get_arg_value(state, host, value) for value in arg]
