Callbacks seem a bit overkill for something like this. I would just get the 
stuff yuu need into variables and then use "shell" or similar to post the 
data to your datastore, but glad you got it working.

On Thursday, June 9, 2016 at 7:36:44 PM UTC+2, Kevin Csuka wrote:
>
> 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/52b81e30-c0a1-4a18-9e92-250c9425e392%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to