你可以在运行 Ansible play 时如何获取输出?

huangapple go评论68阅读模式
英文:

How can I get the output of an Ansible play as it is being run?

问题

默认情况下,Ansible会缓存所有输出(stdoutstderr),然后尝试以可读的方式呈现它。

这是可以启用/禁用的吗?

Ansible尝试以JSON格式呈现所有内容,有时会变得几乎无法阅读,就好像程序尝试输出一个JSON时会变得紧凑。

我能在任务完成之前获取程序传递给Ansible的输出吗?

英文:

By default a
Ansible will cache all the output (stdout and stderr) and then attempts to present it in a readable manner.

Is this something that can be enabled / disabled?

Ansible attempts to present everything in a JSON format and it sometimes ends up being almost unreadable as if the program attempts to output a JSON too it gets compacted.

Can I get the output as it is being given by the program to Ansible rather than wait for the task to finish?

答案1

得分: 0

由于您的帖子包含两个问题,一个关于格式化输出,另一个关于实时或流式日志,我希望专注于主要问题。

是否可以启用/禁用此功能?

不能直接。

我能否在程序将输出提供给Ansible时获取输出,而不必等待任务完成?

这取决于情况。根据模块简介返回值的说明,

Ansible会在通常在远程托管节点上执行每个模块,并收集返回值。

以及

Ansible模块通常返回可以注册到变量中的数据结构...

因此,这种实时输出未实现。还请参阅如何显示实时的 shell stdout

“实时”或“流式”输出尚未合并到Ansible中。 原问题 在2014年被关闭,因为不可行。 较新的提案 自2018年2月以来没有重大更新。

但是,如果需要的话,可以使用自定义模块调试或作为解决方法使用如何显示长时间运行的Ansible任务的进度?

类似的问答

英文:

Since your post contains two questions, one about formatting output and the other about realtime or streaming logs, I like to focus on the main one.


> Is this something that can be enabled / disabled?

Not directly.

> Can I get the output as it is being given by the program to Ansible rather than wait for the task to finish?

It depends. According Introduction to modules and Return Values

> Ansible executes each module, usually on the remote managed node, and collects return values.

and

> Ansible modules normally return a data structure that can be registered into a variable ...

therefore such live output is not implemented. See also How to display realtime shell stdout?

> "Real time" or "streaming" output has not been merged to Ansible yet. The original issue was closed in 2014 as not feasible. A more recent proposal has no major updates since February 2018.

But there is a way if Debugging Custom Modules or as workaround How can I show progress for a long-running Ansible task?

Similar Q&A

huangapple
  • 本文由 发表于 2023年5月10日 21:14:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/76218894.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定