Ansible variable
A named value, such as http_port or site_name, that tasks and templates refer to instead of writing the value in directly.
In more detail
Variables can come from the inventory, group_vars and host_vars files, a play's vars section, role defaults, facts, registered results and the command line. They are inserted with Jinja, as in {{ http_port }}. Keeping values in variables lets one playbook serve every environment, because only the data changes.
Related terms
- variable precedence — The fixed order Ansible uses to decide which value wins when the same variable is set in several places.
- group_vars — A directory whose files hold variables for inventory groups, one file or folder per group, named exactly after the group.
- host_vars — A directory whose files hold variables for single hosts, each file named exactly as the host is spelled in the inventory.
- Jinja — A templating language for Python tools that fills placeholders in text, written inside double curly braces, with values and simple logic.
- fact — A variable Ansible discovers about a host itself, such as its operating system, host name, memory or network addresses.
Taught in
- The Static Inventory File — Ansible Configuration Management at Scale
- Host Groups And Host Variables — Ansible Configuration Management at Scale
- Dynamic Inventory — Ansible Configuration Management at Scale
- Connections And Privilege Escalation — Ansible Configuration Management at Scale
- Check Mode And Diff — Ansible Configuration Management at Scale
- Handlers And Notify — Ansible Configuration Management at Scale
- Variables And Precedence — Ansible Configuration Management at Scale
- Gathering Facts — Ansible Configuration Management at Scale
- Conditionals — Ansible Configuration Management at Scale
- Loops — Ansible Configuration Management at Scale
- Templates With Jinja — Ansible Configuration Management at Scale
- Error Handling With Block, Rescue And Always — Ansible Configuration Management at Scale
- The Standard Directory Layout And Roles — Ansible Configuration Management at Scale
- Writing A Role — Ansible Configuration Management at Scale
- Securing Data With Ansible Vault — Ansible Configuration Management at Scale
- Environment Specific Configuration — Ansible Configuration Management at Scale
- Performance, Forks And Best Practices — Ansible Configuration Management at Scale
- Static Inventories: Hosts, Groups And Groups Of Groups — RHCE in Ansible (EX294): Automate Red Hat Systems
- Inventory Variables: Ranges, group_vars And host_vars — RHCE in Ansible (EX294): Automate Red Hat Systems
- ansible.cfg: Which File Wins, And The Settings That Matter — RHCE in Ansible (EX294): Automate Red Hat Systems
- SSH Keys And An Account For Ansible — RHCE in Ansible (EX294): Automate Red Hat Systems
- Privilege Escalation: sudo Rules And become — RHCE in Ansible (EX294): Automate Red Hat Systems
- Anatomy Of A Playbook: Plays, Tasks And Modules — RHCE in Ansible (EX294): Automate Red Hat Systems
- Variables And Where They Win: group_vars, host_vars And Play Vars — RHCE in Ansible (EX294): Automate Red Hat Systems
- Facts And Magic Variables: Let Each Node Describe Itself — RHCE in Ansible (EX294): Automate Red Hat Systems
- Loops: One Task, Many Items — RHCE in Ansible (EX294): Automate Red Hat Systems
- Conditionals: register, when, changed_when And failed_when — RHCE in Ansible (EX294): Automate Red Hat Systems
- Handlers And Failure: notify, block, rescue And always — RHCE in Ansible (EX294): Automate Red Hat Systems
- ansible-navigator: The Settings File The Exam Reads — RHCE in Ansible (EX294): Automate Red Hat Systems
- Finding Modules In Collections: ansible-doc And navigator — RHCE in Ansible (EX294): Automate Red Hat Systems
- Git And VS Code: Clone, Commit, Push, And The Dev Container — RHCE in Ansible (EX294): Automate Red Hat Systems
- Roles: The Directory Ansible Expects, Defaults And Handlers — RHCE in Ansible (EX294): Automate Red Hat Systems
- RHEL System Roles: timesync And selinux From A Collection — RHCE in Ansible (EX294): Automate Red Hat Systems
- Packages And Repositories: yum_repository And dnf — RHCE in Ansible (EX294): Automate Red Hat Systems
- Users And Groups From A List, With Passwords That Settle — RHCE in Ansible (EX294): Automate Red Hat Systems
- Jinja Templates: One File, A Different Text Per Host — RHCE in Ansible (EX294): Automate Red Hat Systems
- Ansible Vault: Secrets Encrypted, Runs Without A Prompt — RHCE in Ansible (EX294): Automate Red Hat Systems
- Drill: Storage Only Where The Disk Exists — RHCE in Ansible (EX294): Automate Red Hat Systems
- Drill: People, Passwords And sudo From The Vault — RHCE in Ansible (EX294): Automate Red Hat Systems
- Mock Exam, Part 1: Seven Tasks Across Three Sections — RHCE in Ansible (EX294): Automate Red Hat Systems