>
> Found the answer:
>

from ansible.plugins.callback import CallbackBase
import os
import time
import sqlite3

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

try:
    con = sqlite3.connect(dbname)
    cur = con.cursor()
    cur.execute('CREATE TABLE `test3` (`now` TEXT, `host` TEXT UNIQUE, 
`serial` TEXT)')
    con.commit()
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 test3 (now, host, serial) VALUES(?,?,?);",
        (
            now,
            facts.get('ansible_hostname', None),
facts.get('ansible_product_serial', None)
        ))
        con.commit()
    except:
        pass 


Can close.

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/ed39d2a9-6747-404c-85ea-2a146a861d18%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to