Call back script problems

238 views
Skip to first unread message

Gabriel Rosca

unread,
Mar 4, 2016, 7:34:00 PM3/4/16
to Ansible Project
Hi Guys,

I have this callback script. I add callback_whitelist = inventory in ansible.cfg but when I an run get:

 [WARNING]: Failure when attempting to use callback plugin (</usr/share/ansible_plugins/callback_plugins/inventory.CallbackModule object at 0x22a0110>):
runner_on_ok() takes exactly 3 arguments (2 given)


Any Idea ?


#!/usr/bin/python
import os
import time
import sqlite3

dbname = '/etc/ansible/setup.db'
TIME_FORMAT='%Y-%m-%d %H:%M:%S'

try:
    con = sqlite3.connect(dbname)
    cur = con.cursor()
except:
    pass

def log(host, data):

    if type(data) == dict:
        invocation = data.pop('invocation', None)
        if invocation.get('module_name', None) != 'setup':
            return

    facts = data.get('ansible_facts', None)

    now = time.strftime(TIME_FORMAT, time.localtime())

    try:
        # `host` is a unique index
        cur.execute("REPLACE INTO inventory (now, host, arch, dist, distvers, sys,kernel) VALUES(?,?,?,?,?,?,?);",
        (
            now,
            facts.get('ansible_hostname', None),
            facts.get('ansible_architecture', None),
            facts.get('ansible_distribution', None),
            facts.get('ansible_distribution_version', None),
            facts.get('ansible_system', None),
            facts.get('ansible_kernel', None)
        ))
        con.commit()
    except:
        pass

class CallbackModule(object):
    def runner_on_ok(self, host, res):
        log(host, res)


Regards,
Gabriel

Vincent Woo

unread,
Mar 4, 2016, 11:34:11 PM3/4/16
to Ansible Project
I'm also seeing this right now. 

Brian Coca

unread,
Mar 4, 2016, 11:42:17 PM3/4/16
to ansible...@googlegroups.com
first, you don't need to whitelist custom callbacks, that is only for those shipped with ansible as they are disabled by default.

As for the error, you either need to implement all the v2 callbacks and use that to call runner_on_ok or you need to inherit from the new callback base.

   
----------
Brian Coca
Reply all
Reply to author
Forward
0 new messages