本文介绍了Ansible输出格式选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以使用ansible(没有其他任何脚本)来格式化ansible输出?例如
Is there an option to format ansible output with the use of ansible (not any other scripts)? For instance
name: Show version
sudo: true
hosts: web_front_end
tasks:
- name: Create yum cache
shell: yum makecache
- name: Check the version of Portal
shell: rpm -qa | grep portal
register: portal
- debug: msg={{portal.stdout}}
tags:
- portal
- wfe
我只想得到
TASK: [debug msg={{portal.stdout}}]
部分.甚至有没有办法只获得shell命令的输出?
part. Or even is there a way to get only the shell command output?
推荐答案
我有一个用于格式化输出的插件.要点是此处,但要点是:
I have a plugin to format the output. The gist is here but the gist's gist is:
# Save as <folder with your playbook>/callback_plugins/<some name>.py
# Optionally use no_log: True on your playbook/roles/tasks to suppress other output
import sys
import pprint
class CallbackModule(CallbackBase):
def log(self, host, category, data):
pp = pprint.PrettyPrinter(indent=2, stream=sys.stdout)
pp.pprint(data)
这篇关于Ansible输出格式选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!