Add stdout and stdout_lines to the results registered by the yum module

Hi,

I’ve been trying to get some helpful output from playbook runs that use the yum and apt modules.

When I register the results of an invocation of these modules, I notice that the apt module very conveniently returns a “stdout_lines” field which contains something that is much more readable than “msg” or “stdout”, which contain literal "\n"s. But the yum module does not have any such field in its results. There is only a “results” field which is not formatted in a very readable way:

ec2-xxx-xxx-xxx-xxx.compute-1.amazonaws.com | success >> {

“changed”: true,

“msg”: “”,

“rc”: 0,

“results”: [

"Loaded plugins: priorities, update-motd, upgrade-helper\n1018 packages excluded due to repository priority protections\nResolving Dependencies\n → Running transaction check\n—> Package at.x86_64 0:3.1.10-43.8.amzn1 will be updated\n—> Package at.x86_64 0:3.1.10-43.11.amzn1 will be an update\n—> Package audit.x86_64 0:2.3.2-3.19.amzn1 will be updated\n—> Package audit.x86_64 0:2.3.3-4.21.amzn1 will be an update\n—> Package audit-libs.i686 0:2.3.2-3.19.amzn1 will be updated\n—> Package audit-libs.x86_64 0:2.3.2-3.19.amzn1 will be updated\n—> Package audit-libs.i686 0:2.3.3-4.21.amzn1 will be an update\n—> Package audit-libs.x86_64 0:2.3.3-4.21.amzn1 will be an update\n—> Package aws-amitools-ec2.noarch 0:1.5.2-0.0.amzn1 will be updated\n—> Package aws-amitools-ec2.noarch 0:1.5.6-1.1.amzn1 will be an update\n—> Package aws-apitools-as.noarch 0:1.0.61.5-1.0.amzn1 will be updated\n—> Package aws-apitools-as.noarch 0:1.0.61.6-1.0.amzn1 will be an update\n—> Package aws-apitools-ec2.noarch 0:1.6.13.0-1.1.amzn1 will be updated\n—> Package aws-apitools-ec2.noarch 0:1.7.1.3-1.0.amzn1 will be an update\n—> Package aws-apitools-elb.noarch 0:1.0.34.0-1.0.amzn1 will be updated\n—> Package aws-apitools-elb.noarch 0:1.0.35.0-1.0.amzn1 will be an update\n—> Package aws-apitools-rds.noarch 0:1.15.001-1.0.amzn1 will be updated\n—> Package aws-apitools-rds.noarch 0:1.18.001-1.0.amzn…

I’m snipping the rest of it, but you get the idea.

Is it possible to introduce a “stdout_lines” in the output of the yum module as well?

Thanks!

In comparison, here is the output of the apt module, with the stdout_lines field that I find readable:

open a feature request on github for the ansible-modules-core project, this should not be hard to add

Hi Brian,

I am concerned with ansible-playbook, and so I’ll restrict my observations to the context of playbook executions only.

I examined the source code and there is a marked difference in the way the apt and yum modules deal with the outputs captured from their respective actions. The difference is in what is passed to the exit_json() call which passes information back to playbook.

  1. apt.py sends stdout in a key called stdout and stderr in a key called stderr
  2. yum.py, on the other hand, puts stdout into a results key and stderr into the msg key
    playbook/init.py contains instructions to split anything returned as stdout into lines, and put that into stdout_lines, which is what we want.

Therefore I feel that the yum module is behaving in a non-standard way here and its information returning style must be revised to make it more aligned with what the apt module does. If this seems like the right course of action, I can work on the yum module code and submit a PR.

Awaiting your comments/suggestions.

Regards,
Sankalp

Actually the yum module output is more consistent with what you would expect registering a var using with_items. Both modules use a special optimization in which they slurp the whole list instead of executing it one at a time.

Also I think you are comparing outputs on different operations. In any case a quick workaround is to add .split() to the yum output to get the same output as stdout_lines.