Ansible output formatting options

安稳与你 提交于 2019-12-06 01:33:15

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)

You basically have two choices. One is to do what folks have described above, which is to pipe the output of the ansible command to things like perl, sed, awk, etc.

The second alternative is to write your own Python script that calls ansible directly. Ansible is written in Python and as such you can call it directly from your own Python code. The Ansible documentation on its Python API provides details on how to do this.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!