Quiz Entry - updated: 2026.11.05
What does register do in a task, and what does the captured variable contain?
register: name saves the task's result (the module's return data) in a variable. Later tasks can print it with debug, or use it to make decisions, for example run a step only if the previous one changed something.
- name: Installs a package and prints the result
hosts: all
tasks:
- name: Install the package
ansible.builtin.dnf:
name: httpd
state: installed
register: install_result
- ansible.builtin.debug:
var: install_result
On a host where httpd was already there, the debug task prints something like:
"install_result": {
"changed": false,
"msg": "",
"rc": 0,
"results": ["httpd-2.4.51-7.el9_0.x86_64 providing httpd is already installed"]
}
Note that register is a task keyword: it sits at the same level as the module name, not inside the module's arguments. What the variable holds depends on the module, but common keys are changed, failed, rc (return code), stdout/stderr for command modules, and content for uri with return_content: true.
Go deeper:
Registering variables (official docs) — what gets stored and how long it lives.
ansible.builtin.debug module (official docs) —
varversusmsg.