Ansible标准格式 [英] Ansible stdout Formatting

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

问题描述

承担以下任务:

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

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

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

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

我收到以下输出:

"msg":输出:[u'some_value',u'some_value2,u'some_value3]"

如何使输出打印为?

"msg":

输出:

some_value

some_value2

some_value3

可用的版本是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中为全局文件,或在Playbook/项目中为本地文件),然后在[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

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

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