2018-04-25 20:18:52 +02:00
.. _common_return_values:
2017-01-10 02:18:15 +01:00
Return Values
-------------
2015-03-13 16:43:02 +01:00
.. contents :: Topics
2017-08-29 17:59:41 +02:00
Ansible modules normally return a data structure that can be registered into a variable, or seen directly when output by
2019-03-27 23:00:21 +01:00
the `ansible` program. Each module can optionally document its own unique return values (visible through ansible-doc and on the :ref: `main docsite<ansible_documentation>` ).
2016-09-02 00:37:37 +02:00
2017-08-29 17:59:41 +02:00
This document covers return values common to all modules.
2016-09-02 00:37:37 +02:00
.. note :: Some of these keys might be set by Ansible itself once it processes the module's return information.
2015-03-13 16:43:02 +01:00
2017-01-10 02:18:15 +01:00
Common
^^^^^^
2015-03-13 16:43:02 +01:00
2016-09-07 17:50:55 +02:00
backup_file
`` ` ` ` ` ` ` ` ``
For those modules that implement `backup=no|yes` when manipulating files, a path to the backup file created.
2020-08-07 23:04:19 +02:00
.. code-block :: console
"backup_file": "./foo.txt.32729.2020-07-30@06:24:19~"
2016-09-01 18:21:07 +02:00
changed
`` ` ` ` ``
2016-09-02 00:37:37 +02:00
A boolean indicating if the task had to make changes.
2015-03-13 16:43:02 +01:00
2020-08-07 23:04:19 +02:00
.. code-block :: console
"changed": true
2019-11-19 15:46:59 +01:00
diff
`` ``
Information on differences between the previous and current state. Often a dictionary with entries `` before `` and `` after `` , which will then be formatted by the callback plugin to a diff view.
2020-08-07 23:04:19 +02:00
.. code-block :: console
"diff": [
{
"after": "",
"after_header": "foo.txt (content)",
"before": "",
"before_header": "foo.txt (content)"
},
{
"after_header": "foo.txt (file attributes)",
"before_header": "foo.txt (file attributes)"
}
2016-09-01 18:21:07 +02:00
failed
`` ` ` ``
A boolean that indicates if the task was failed or not.
2020-08-07 23:04:19 +02:00
.. code-block :: console
"failed": false
2016-09-01 18:21:07 +02:00
invocation
`` ` ` ` ` ` ` ``
Information on how the module was invoked.
2020-08-07 23:04:19 +02:00
.. code-block :: console
"invocation": {
"module_args": {
"_original_basename": "foo.txt",
"attributes": null,
"backup": true,
"checksum": "da39a3ee5e6b4b0d3255bfef95601890afd80709",
"content": null,
"delimiter": null,
"dest": "./foo.txt",
"directory_mode": null,
"follow": false,
"force": true,
"group": null,
"local_follow": null,
"mode": "666",
"owner": null,
"regexp": null,
"remote_src": null,
"selevel": null,
"serole": null,
"setype": null,
"seuser": null,
"src": "/Users/foo/.ansible/tmp/ansible-tmp-1596115458.110205-105717464505158/source",
"unsafe_writes": null,
"validate": null
}
2016-09-01 18:21:07 +02:00
msg
`` `
2016-09-02 00:37:37 +02:00
A string with a generic message relayed to the user.
2016-09-01 18:21:07 +02:00
2020-08-07 23:04:19 +02:00
.. code-block :: console
"msg": "line added"
2016-09-01 18:21:07 +02:00
rc
``
2020-09-04 21:44:13 +02:00
Some modules execute command line utilities or are geared for executing commands directly (raw, shell, command, and so on), this field contains 'return code' of these utilities.
2015-03-13 16:43:02 +01:00
2020-08-07 23:04:19 +02:00
.. code-block :: console
"rc": 257
2016-09-01 18:21:07 +02:00
results
`` ` ` ` ``
If this key exists, it indicates that a loop was present for the task and that it contains a list of the normal module 'result' per item.
2020-08-07 23:04:19 +02:00
.. code-block :: console
"results": [
{
"ansible_loop_var": "item",
"backup": "foo.txt.83170.2020-07-30@07:03:05~",
"changed": true,
"diff": [
{
"after": "",
"after_header": "foo.txt (content)",
"before": "",
"before_header": "foo.txt (content)"
},
{
"after_header": "foo.txt (file attributes)",
"before_header": "foo.txt (file attributes)"
}
],
"failed": false,
"invocation": {
"module_args": {
"attributes": null,
"backrefs": false,
"backup": true
}
},
"item": "foo",
"msg": "line added"
},
{
"ansible_loop_var": "item",
"backup": "foo.txt.83187.2020-07-30@07:03:05~",
"changed": true,
"diff": [
{
"after": "",
"after_header": "foo.txt (content)",
"before": "",
"before_header": "foo.txt (content)"
},
{
"after_header": "foo.txt (file attributes)",
"before_header": "foo.txt (file attributes)"
}
],
"failed": false,
"invocation": {
"module_args": {
"attributes": null,
"backrefs": false,
"backup": true
}
},
"item": "bar",
"msg": "line added"
}
]
2016-09-01 18:21:07 +02:00
skipped
`` ` ` ` ``
A boolean that indicates if the task was skipped or not
2020-08-07 23:04:19 +02:00
.. code-block :: console
"skipped": true
2016-09-01 18:21:07 +02:00
stderr
`` ` ` ``
2020-09-04 21:44:13 +02:00
Some modules execute command line utilities or are geared for executing commands directly (raw, shell, command, and so on), this field contains the error output of these utilities.
2015-03-13 16:43:02 +01:00
2020-08-07 23:04:19 +02:00
.. code-block :: console
"stderr": "ls: foo: No such file or directory"
2016-09-01 18:21:07 +02:00
stderr_lines
`` ` ` ` ` ` ` ` ` ``
2017-08-29 17:59:41 +02:00
When `stderr` is returned we also always provide this field which is a list of strings, one item per line from the original.
2015-03-13 16:43:02 +01:00
2020-08-07 23:04:19 +02:00
.. code-block :: console
"stderr_lines": [
"ls: doesntexist: No such file or directory"
]
2016-09-01 18:21:07 +02:00
stdout
2015-03-13 16:43:02 +01:00
`` ` ` ``
2020-09-04 21:44:13 +02:00
Some modules execute command line utilities or are geared for executing commands directly (raw, shell, command, and so on). This field contains the normal output of these utilities.
2015-03-13 16:43:02 +01:00
2020-08-07 23:04:19 +02:00
.. code-block :: console
"stdout": "foo!"
2016-09-01 18:21:07 +02:00
stdout_lines
`` ` ` ` ` ` ` ` ` ``
2017-08-29 17:59:41 +02:00
When `stdout` is returned, Ansible always provides a list of strings, each containing one item per line from the original output.
2015-03-13 16:43:02 +01:00
2020-08-07 23:04:19 +02:00
.. code-block :: console
"stdout_lines": [
"foo!"
]
2017-01-09 21:54:45 +01:00
2017-01-10 02:18:15 +01:00
.. _internal_return_values:
2016-09-01 18:21:07 +02:00
Internal use
2017-01-10 02:18:15 +01:00
^^^^^^^^^^^^
2017-01-09 21:54:45 +01:00
2016-09-02 00:37:37 +02:00
These keys can be added by modules but will be removed from registered variables; they are 'consumed' by Ansible itself.
2015-03-13 16:43:02 +01:00
2016-09-01 18:21:07 +02:00
ansible_facts
`` ` ` ` ` ` ` ` ` ` ``
This key should contain a dictionary which will be appended to the facts assigned to the host. These will be directly accessible and don't require using a registered variable.
2015-03-13 16:43:02 +01:00
2016-09-01 18:21:07 +02:00
exception
`` ` ` ` ` ` ``
2016-09-02 00:37:37 +02:00
This key can contain traceback information caused by an exception in a module. It will only be displayed on high verbosity (-vvv).
2015-03-13 16:43:02 +01:00
2016-09-01 18:21:07 +02:00
warnings
`` ` ` ` ` ``
This key contains a list of strings that will be presented to the user.
2015-03-13 16:43:02 +01:00
2017-02-14 05:49:39 +01:00
deprecations
`` ` ` ` ` ` ` ` ` ``
This key contains a list of dictionaries that will be presented to the user. Keys of the dictionaries are `msg` and `version` , values are string, value for the `version` key can be an empty string.
2015-03-13 16:43:02 +01:00
.. seealso ::
2020-09-10 17:48:28 +02:00
:ref: `list_of_collections`
Browse existing collections, modules, and plugins
2018-10-08 21:24:19 +02:00
`GitHub modules directory <https://github.com/ansible/ansible/tree/devel/lib/ansible/modules> `_
Browse source of core and extras modules
2018-07-21 15:48:47 +02:00
`Mailing List <https://groups.google.com/group/ansible-devel> `_
2015-03-13 16:43:02 +01:00
Development mailing list
`irc.freenode.net <http://irc.freenode.net> `_
#ansible IRC chat channel