Ansible标准格式 [英] Ansible stdout Formatting
问题描述
承担以下任务:
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屋!