Ansible 标准输出格式 [英] Ansible stdout Formatting

查看:46
本文介绍了Ansible 标准输出格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设以下任务:

shell: "some_script.sh"
 register: "some_script_result"

debug:
   msg: "Output: {{ some_script_result.stdout_lines }}

我收到以下输出:

"msg": "Output: [u'some_value',u'some_value2,u'some_value3]"

如何让输出打印为?

"msg":
Output:
some_value
some_value2
some_value3

Ansible 版本为 2.4.2.

Ansible version is 2.4.2.

谢谢!

推荐答案

尝试 这个 选项.你会喜欢的.

Try this option. You’ll love it.

Ansible 2.5 引入了一个新的 YAML 回调插件——这意味着任何运行 Ansible 2.5.0 或更高版本的机器都可以自动开始使用这种格式,而无需安装自定义插件.

There's a new YAML callback plugin introduced with Ansible 2.5 — meaning any machine running Ansible 2.5.0 or later can automatically start using this format without installing custom plugins.

要使用它,请编辑您的 ansible.cfg 文件(全局的,在/etc/ansible/ansible.cfg 中,或在您的剧本/项目中的本地文件),并在 [defaults] 部分下添加以下几行:

To use it, edit your ansible.cfg file (either global, in /etc/ansible/ansible.cfg, or a local one in your playbook/project), and add the following lines under the [defaults] section:

# Use the YAML callback plugin.
stdout_callback = yaml
# Use the stdout_callback when running ad-hoc commands.
bin_ansible_callbacks = True

现在我可以轻松阅读您的输出消息

Now I can easily read through your output message

如果出现以下错误:

ERROR! Invalid callback for stdout specified: yaml

运行

ansible-galaxy collection install community.general

这篇关于Ansible 标准输出格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆