相关疑难解决方法(0)

通用Ansible的回调运行?

我已经定义了一个回调,如下所示:

#!/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

1
推荐指数
1
解决办法
2312
查看次数

标签 统计

ansible ×1