我已经定义了一个回调,如下所示:
#!/usr/bin/env python2.7
# -*- coding: utf-8 -*-
import sys
import pprint
from ansible.plugins.callback import CallbackBase
class JSONPrettyPrintCallback(CallbackBase):
printer = pprint.PrettyPrinter(indent=4, stream=sys.stdout)
def log(self, host, category, data):
# one json blob to rule them all
self.printer.pprint({'host': host, 'category': category, 'data': data})
Run Code Online (Sandbox Code Playgroud)
在我的Ansible配置中,我定义了路径:
[defaults]
callback_plugins = callback_plugins/
Run Code Online (Sandbox Code Playgroud)
但是,当我运行我的模块时,我仍然看到默认的Ansible输出:
10.0.0.1 | SUCCESS => {
...
}
Run Code Online (Sandbox Code Playgroud)
我正在运行它:
ansible all -u myuser -m script -a 'path/to/script.py'
Run Code Online (Sandbox Code Playgroud)
我需要做些什么才能正确格式化输出?
如果要替换Ansible标准输出,则应将stdout_callback参数设置为回调.
更新: stdout_callback参数将仅影响ansible-playbookCLI输出,如注释中正确指出的那样.
我已经调查了一下代码,ansibleCLI仅支持minimal和oneline(如果-o设置了选项)stdout回调.
更改输出行为的最简单方法是放入./callback_plugins/minimal.pyplaybook文件夹并根据需要进行修改.
或者您可以修补adhoc.py以便能够接受其他标准插件.
| 归档时间: |
|
| 查看次数: |
2312 次 |
| 最近记录: |