Ansible Module Return Value

From NovaOrdis Knowledge Base
Jump to navigation Jump to search

External

Internal

Overview

Ansible modules return after execution a data structure that can be registered into a variable with the task's register: keyword. All modules return a set of common keys, documented below in the "Common Return Keys" section. Each module may choose to return keys specific to the module, described in the module's documentation.

For example, the execution of a command tasks produces the following return value map:

cmd:
 - "sh"
 - "-l"
 - "/tmp"
failed: false
stdout: "lrwxr-xr-x@ 1 root  admin  11 Sep 21  2020 /tmp -> private/tmp"
stdout_lines:
  - "lrwxr-xr-x@ 1 root  admin  11 Sep 21  2020 /tmp -> private/tmp"
stderr: ""
stderr_lines: []
start: "2021-07-03 23:39:57.499748"
end: "2021-07-03 23:39:57.506848"
changed: false
delta: "0:00:00.007100"
rc: 0

Common Return Keys

The content of execution stdout and stderr can be accessed with variable_name.stdout, variable_name.stderr, the failure situation with variable_name.failed, etc. A typical pattern is to use the task output accessible through registered variables and conditionally perform actions based on the registered variables values.