Registering variables
You can create a variable from the output of an Ansible task with the task keywordregister. You can use the registered variable in any later task in your play. For example:
For more examples of using registered variables in conditions on later tasks, seeConditionals. Registered variables may be simple variables, list variables, dictionary variables, or complex nested data structures. The documentation for each module includes aRETURNsection that describes the return values for that module. To see the values for a particular task, run your playbook with-v.
Registered variables are stored in memory. You cannot cache registered variables for use in future playbook runs. A registered variable is valid only on the host for the rest of the current playbook run, including subsequent plays within the same playbook run.
Registered variables are host-level variables. When you register a variable in a task with a loop, the registered variable contains a value for each item in the loop. The data structure placed in the variable during the loop contains aresultsattribute, which is a list of all responses from the module. For a more in-depth example of how this works, see theLoopssection on using register with a loop.
If a task fails or is skipped, Ansible still registers a variable with a failure or skipped status, unless the task is skipped based on tags. SeeTagsfor information on adding and using tags.