Skip to content

ansible.builtin.shell invocations through ansible-runner sometimes do not return documented return values #1381

@ZachOldham

Description

@ZachOldham

We are observing that when we invoke the ansible.builtin.shell module via ansible_runner.run, the res field of runner_on_ok events is sometimes an empty dict, despite the documentation for the ansible.builtin.shell module claiming that it always returns certain values. We are using ansible-core version 2.16.6 and ansible-runner version 2.3.6.

We use ansible-runner to invoke ansible.builtin.shell to run a script on 15 machines simultaneously. When we do this, we usually have no problems, the script succeeds on every machine, and we see that the the res dict of the runner_on_ok events contain the fields documented in ansible.builtin.shell. On occasion (maybe 1/4 of the time?) we will see that the res dict of the runner_on_ok events for some machines is empty, while is is populated for the rest of the machines. Each time this happens, it is the same two machines that have empty res dicts. When we examine the logs, it is clear that the script has also run successfully on those machines, which is consistent with the fact we get a runner_on_ok event from them as well.

This is extremely confusing as the scripts are running correctly and we are getting a runner_on_ok event, but it is missing the fields that the module is documented to always return. This means that we don't get the return code, stdout, or stderr, which we need later.

We know that the underlying issue is the event having an empty res dict as we log the res of every terminal event (runner_on_unreachable, runner_on_failed, runner_on_ok) and we see that for these machines there is sometimes an empty res dict ({}) while for all the other machines there is a correctly populated res dict like:

{
  "changed": true,
  "stdout": "",
  "stderr": "<STDERR>",
  "rc": 0,
  "cmd": "<CMD>",
  "start": "2024-07-19 19:06:18.744817",
  "end": "2024-07-19 19:06:50.576242",
  "delta": "0:00:31.831425",
  "msg": "",
  "invocation": {
    "module_args": {
      "chdir": "/tmp",
      "_raw_params": "<PARAMS>",
      "_uses_shell": true,
      "expand_argument_vars": true,
      "stdin_add_newline": true,
      "strip_empty_ends": true,
      "argv": null,
      "executable": null,
      "creates": null,
      "removes": null,
      "stdin": null
    }
  },
  "stdout_lines": [],
  "stderr_lines": [
    <STDERR_LINES>
  ],
  "_ansible_no_log": false,
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions