ansible  2.9.27
About: Ansible is an IT Configuration Management, Deployment \
About: Ansible (2.x) is an IT Configuration Management, Deployment & Orchestration tool.
ansible download page.
  Fossies Dox: ansible-2.9.27.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

ansible.template Namespace Reference


namespace  native_helpers
namespace  safe_eval
namespace  template
namespace  vars


class  AnsibleContext
class  AnsibleEnvironment
class  AnsibleUndefined
class  JinjaPluginIntercept
class  Templar


def generate_ansible_template_vars (path, dest_path=None)
def _escape_backslashes (data, jinja_env)
def is_template (data, jinja_env)
def _count_newlines_from_end (in_str)
def recursive_check_defined (item)


 __metaclass__ = type
 display = Display()
list __all__ = ['Templar', 'generate_ansible_template_vars']
tuple NON_TEMPLATED_TYPES = (bool, Number)
string JINJA2_OVERRIDE = '#jinja2:'
bool USE_JINJA2_NATIVE = False
 JINJA2_BEGIN_TOKENS = frozenset(('variable_begin', 'block_begin', 'comment_begin', 'raw_begin'))
 JINJA2_END_TOKENS = frozenset(('variable_end', 'block_end', 'comment_end', 'raw_end'))

Function Documentation

◆ _count_newlines_from_end()

def ansible.template._count_newlines_from_end (   in_str)
Counts the number of newlines at the end of a string. This is used during
the jinja2 templating to ensure the count matches the input, since some newlines
may be thrown away during the templating.

Definition at line 198 of file

References ansible.template._count_newlines_from_end().

Referenced by ansible.template._count_newlines_from_end(), and ansible.template.Templar.do_template().

◆ _escape_backslashes()

def ansible.template._escape_backslashes (   data,
Double backslashes within jinja2 expressions

A user may enter something like this in a playbook::

    msg: "Test Case 1\\3; {{ test1_name | regex_replace('^(.*)_name$', '\\1')}}"

The string inside of the {{ gets interpreted multiple times First by yaml.
Then by python.  And finally by jinja2 as part of it's variable.  Because
it is processed by both python and jinja2, the backslash escaped
characters get unescaped twice.  This means that we'd normally have to use
four backslashes to escape that.  This is painful for playbook authors as
they have to remember different rules for inside vs outside of a jinja2
expression (The backslashes outside of the "{{ }}" only get processed by
yaml and python.  So they only need to be escaped once).  The following
code fixes this by automatically performing the extra quoting of
backslashes inside of a jinja2 expression.

Definition at line 122 of file

References ansible.template._escape_backslashes(), and

Referenced by ansible.template._escape_backslashes(), and ansible.template.Templar.do_template().

◆ generate_ansible_template_vars()

◆ is_template()

def ansible.template.is_template (   data,
This function attempts to quickly detect whether a value is a jinja2
template. To do so, we look for the first 2 matching jinja2 tokens for
start and end delimiters.

Definition at line 165 of file

References ansible.template.is_template(), and

Referenced by ansible.plugins.strategy.StrategyBase._set_hosts_cache(), and ansible.template.is_template().

◆ recursive_check_defined()

def ansible.template.recursive_check_defined (   item)

Variable Documentation

◆ __all__

list ansible.template.__all__ = ['Templar', 'generate_ansible_template_vars']

Definition at line 60 of file

◆ __metaclass__

ansible.template.__metaclass__ = type

Definition at line 20 of file

◆ display

ansible.template.display = Display()

Definition at line 57 of file


ansible.template.JINJA2_BEGIN_TOKENS = frozenset(('variable_begin', 'block_begin', 'comment_begin', 'raw_begin'))

Definition at line 90 of file


ansible.template.JINJA2_END_TOKENS = frozenset(('variable_end', 'block_end', 'comment_end', 'raw_end'))

Definition at line 91 of file


string ansible.template.JINJA2_OVERRIDE = '#jinja2:'

Definition at line 68 of file


tuple ansible.template.NON_TEMPLATED_TYPES = (bool, Number)

Definition at line 66 of file


bool ansible.template.USE_JINJA2_NATIVE = False

Definition at line 72 of file