0Pricing
Ansible Academy · Lesson

Variables & Expressions in Jinja2

Inject values into the template.

Variables Inside Templates

Every variable available to your play is also available in the template. Just wrap its name in {{ }} to print the value. 🌟

server_name {{ domain }};
worker_processes {{ cpu_count }};

Accessing Dictionary Keys

For a dictionary variable, reach a key with dot or bracket notation. Both db.host and db['host'] return the same value.

host = {{ db.host }}
port = {{ db['port'] }}

All lessons in this course

  1. The template Module & .j2 Files
  2. Variables & Expressions in Jinja2
  3. Loops & if Blocks in Templates
  4. Filters: default, join & upper
← Back to Ansible Academy