0Pricing
Ansible Academy · Lesson

Defining & Using vars in a Play

Declare values and reference them.

Why Variables Exist

Hardcoding values like a port or package name everywhere makes change painful. A variable names a value once so you can reuse it. 🌟

The vars Section

Inside a play you add a vars key holding a mapping of names to values. Everything under it becomes available to that play's tasks.

- hosts: web
  vars:
    http_port: 80
    app_name: shop
  tasks: []

All lessons in this course

  1. Defining & Using vars in a Play
  2. The {{ }} Substitution Syntax
  3. Extra Vars on the Command Line
  4. Where Variables Come From & Precedence
← Back to Ansible Academy