Ansible uses Jinja2 templating to enable dynamic expressions and access to variables. Ansible includes a lot of specialized filters and tests for templating. You can use all the standard filters and tests included in Jinja2 as well. Ansible also offers a new plugin type: Lookup Plugins.
All templating happens on the Ansible controller before the task is sent and executed on the target machine. This approach minimizes the package requirements on the target (jinja2 is only required on the controller). It also limits the amount of data Ansible passes to the target machine. Ansible parses templates on the controller and passes only the information needed for each task to the target machine, instead of passing all the data on the controller and parsing it on the target.
- Using filters to manipulate data
- Handling undefined variables
- Defining different values for true/false/null (ternary)
- Managing data types
- Formatting data: YAML and JSON
- Combining and selecting data
- Randomizing data
- Managing list variables
- Selecting from sets or lists (set theory)
- Calculating numbers (math)
- Managing network interactions
- Encrypting and checksumming strings and passwords
- Manipulating text
- Manipulating strings
- Managing UUIDs
- Handling dates and times
- Getting Kubernetes resource names
- Python3 in templates
New in version 2.8.
now() Jinja2 function retrieves a Python datetime object or a string representation for the current time.
now() function supports 2 arguments:
Trueto get the current time in UTC. Defaults to
Accepts a strftime string that returns a formatted date time string.
- Intro to playbooks
An introduction to playbooks
Conditional statements in playbooks
Looping in playbooks
Playbook organization by roles
- Tips and tricks
Tips and tricks for playbooks
- User Mailing List
Have a question? Stop by the google group!
#ansible IRC chat channel