The {{ }} Substitution Syntax
Inject variables into strings and args.
The {{ }} Substitution Syntax is a free DevOps Bootcamp lesson on CoddyKit. This is lesson 2 of 4. Any 3 lessons of this learning path are free to read in full — after that, CoddyKit PRO unlocks every lesson, plus hands-on practice with a built-in code editor and a 24/7 AI tutor. It is part of the DevOps Bootcamp learning path, and your progress syncs across the web and the CoddyKit app. The DevOps Bootcamp course includes 4 lessons in total.
Meet Jinja2
The double curly braces come from Jinja2, the templating engine Ansible uses. Anything inside them is an expression to evaluate. 🌟
The Basic Substitution
At its simplest, {{ name }} is replaced with the value of name. Ansible evaluates it before the module runs.
msg: "Welcome, {{ name }}!"Mind the Spaces
Spaces inside the braces are conventional and ignored: {{ name }} equals {{name}}. The readable, spaced form is the standard style.
Quote When It Starts a Value
If a value begins with braces, YAML needs quotes around the whole string. Otherwise it mistakes it for a dictionary.
name: "{{ app_name }}"Combine Text and Variables
You can mix literal text with substitutions freely in one string, building up paths or messages piece by piece.
path: "/var/www/{{ site_name }}/index.html"Access Dictionary Keys
For a dictionary variable, reach a key with dot or bracket notation. Both db.port and db['port'] return the same value.
msg: "DB on {{ db.host }}:{{ db.port }}"Access List Items
Index into a list variable with brackets. Counting starts at zero, so packages[0] is the first element.
msg: "First package is {{ packages[0] }}"Expressions, Not Just Names
Braces can hold real expressions: math, comparisons, even concatenation. Ansible evaluates the whole thing.
msg: "Total: {{ workers * 2 }}"Filters Transform Values
A pipe applies a filter to reshape a value. Here upper turns the string into capitals before printing.
msg: "{{ region | upper }}"Braces Only in Strings
Substitution lives in string values. A bare key like name still needs its value quoted when it leads with {{ }}.
Watch for Undefined
Referencing a name that was never set raises an undefined variable error. Define it first, or supply a default filter.
msg: "{{ tier | default('web') }}"Quick Check
Why does name: {{ app_name }} need quotes?
Recap
You now substitute values with {{ }}, reach into lists and dictionaries, apply filters, and quote leading braces. ✨
Learn DevOps Bootcamp with an AI tutor — free
Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.
- Courses
- 142
- Lessons
- 568
Frequently Asked Questions
Is the “The {{ }} Substitution Syntax” lesson free?
Yes — any 3 lessons of the DevOps Bootcamp learning path, including “The {{ }} Substitution Syntax”, are free to read in full here on the web. After that, CoddyKit PRO unlocks every lesson, plus interactive practice with a built-in code editor and a 24/7 AI tutor. The DevOps Bootcamp course includes 4 lessons in total.
What will I learn in “The {{ }} Substitution Syntax”?
Inject variables into strings and args. You practise DevOps Bootcamp with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start DevOps Bootcamp?
No prior experience is required. DevOps Bootcamp on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 2 of 4.
How long does the “The {{ }} Substitution Syntax” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this DevOps Bootcamp lesson?
Yes. Every DevOps Bootcamp lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Defining & Using vars in a Play
- The {{ }} Substitution Syntax
- Extra Vars on the Command Line
- Where Variables Come From & Precedence