LOGBOOK

HELP

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.

Flow: a task runs a module, register stores the returned JSON in install_result, a later debug task prints it or a when condition uses it

- 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:

From Quiz: ITIA / Ansible Variables, Secrets and Facts | Updated: Nov 05, 2026