'Templates (possibly recursively) any given data as input. If convert_bare is
set to True, the given data will be wrapped as a jinja2 variable (\'{{foo}}\')
before being sent through the template engine.'

def template(self, variable, convert_bare=False, preserve_trailing_newlines=True, escape_backslashes=True, fail_on_undefined=None, overrides=None, convert_data=True, static_vars=[''], cache=True, bare_deprecated=True, disable_lookups=False):

    if hasattr(variable, '__UNSAFE__'):
        return variable
    if (fail_on_undefined is None):
        fail_on_undefined = self._fail_on_undefined_errors
    try:
        if convert_bare:
            variable = self._convert_bare_variable(variable, bare_deprecated=bare_deprecated)
        if isinstance(variable, string_types):
            result = variable
            if self._contains_vars(variable):
                only_one = self.SINGLE_VAR.match(variable)
                if only_one:
                    var_name = only_one.group(1)
                    if (var_name in self._available_variables):
                        resolved_val = self._available_variables[var_name]
                        if isinstance(resolved_val, NON_TEMPLATED_TYPES):
                            return resolved_val
                        elif (resolved_val is None):
                            return C.DEFAULT_NULL_REPRESENTATION
                sha1_hash = None
                if cache:
                    variable_hash = sha1(text_type(variable).encode('utf-8'))
                    options_hash = sha1((((text_type(preserve_trailing_newlines) + text_type(escape_backslashes)) + text_type(fail_on_undefined)) + text_type(overrides)).encode('utf-8'))
                    sha1_hash = (variable_hash.hexdigest() + options_hash.hexdigest())
                if (cache and (sha1_hash in self._cached_result)):
                    result = self._cached_result[sha1_hash]
                else:
                    result = self.do_template(variable, preserve_trailing_newlines=preserve_trailing_newlines, escape_backslashes=escape_backslashes, fail_on_undefined=fail_on_undefined, overrides=overrides, disable_lookups=disable_lookups)
                    unsafe = hasattr(result, '__UNSAFE__')
                    if (convert_data and (not self._no_type_regex.match(variable))):
                        if ((result.startswith('{') and (not result.startswith(self.environment.variable_start_string))) or result.startswith('[') or (result in ('True', 'False'))):
                            eval_results = safe_eval(result, locals=self._available_variables, include_exceptions=True)
                            if (eval_results[1] is None):
                                result = eval_results[0]
                                if unsafe:
                                    result = wrap_var(result)
                            else:
                                pass
                    if cache:
                        self._cached_result[sha1_hash] = result
            return result
        elif isinstance(variable, (list, tuple)):
            return [self.template(v, preserve_trailing_newlines=preserve_trailing_newlines, fail_on_undefined=fail_on_undefined, overrides=overrides, disable_lookups=disable_lookups) for v in variable]
        elif isinstance(variable, dict):
            d = {}
            for k in variable.keys():
                if (k not in static_vars):
                    d[k] = self.template(variable[k], preserve_trailing_newlines=preserve_trailing_newlines, fail_on_undefined=fail_on_undefined, overrides=overrides, disable_lookups=disable_lookups)
                else:
                    d[k] = variable[k]
            return d
        else:
            return variable
    except AnsibleFilterError:
        if self._fail_on_filter_errors:
            raise
        else:
            return variable
