register
The task keyword that saves a task's result in a named variable so later tasks can read it.
In more detail
For a command task the saved result includes stdout, the output text, and rc, the return code, so a later debug task can print id_result.stdout. Conditions often test registered results, for example to run a step only when an earlier one succeeded.
Example
register: id_resultRelated terms
- task result — The report a module sends back for each host: a status such as ok, changed, failed, unreachable or skipped, plus data in JSON.
- command module — The module that runs any program you name on the host and reports what it printed, without being able to tell whether it changed anything.
- when condition — A task keyword holding an expression; the task runs on a host only if the expression is true there, and is reported as skipped otherwise.
- standard output and standard error — The two channels a program writes normal output (stdout) and error messages (stderr) to, plus stdin for input.
Taught in
- Connections And Privilege Escalation — Ansible Configuration Management at Scale
- Conditionals — Ansible Configuration Management at Scale
- Variables And Where They Win: group_vars, host_vars And Play Vars — 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
- Services And Boot Targets: Started Is Not Enabled — RHCE in Ansible (EX294): Automate Red Hat Systems
- File Systems And Mounts: mounted, present And UUIDs — RHCE in Ansible (EX294): Automate Red Hat Systems
- SELinux: Labels, Ports And Booleans That Persist — RHCE in Ansible (EX294): Automate Red Hat Systems