Hello,
I am trying to write my own callback function which logs information which I want to database, especially informations from local facts.
We have localfacts in json mode and I can easly get access to them from Ansbile it self, however everything what I’ve tried in terms access them from callback function failed.
Details:
- My callback function script skeleton is based on this callback script: http://jpmens.net/2012/09/11/watching-ansible-at-work-callbacks/
- I’ve search ansible group and found something similar - however didn’t help solve my problem (https://groups.google.com/forum/#!topic/ansible-project/3GvdIIWCdSI)
- Looking in source (ansible / plugins / callbacks /) is not so helpfull for me as well.
So question, how I can get access to fact stored in local facts in callback functions:
-
These is a file on remote host:
/etc/ansible/facts.d/apache.fact -
Return from this file (json format):
{
“name”: “apache”,
“status”: “Installed”,
“version”: “1.0.8”
} -
Return this fact in ansible-playbook
“msg”: “work - variable: {u’apache’: {u’status’: u’Installed’, u’version’: u’1.0.8’, u’name’: u’apache’}}” -
Access to it from my callback function (Based on this callback which I mentioned above).
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),
… # !!! Works well
))
con.commit()
cur.execute(“REPLACE INTO modules (host, name, status, version) VALUES(?,?,?,?);”,
(
# !!! - Not working !!!
facts.get(‘ansible_hostname’, None),
facts.get(‘ansible_local.apache.name’, None),
facts.get(‘ansible_local.apache.status’, None),
facts.get(‘ansible_local.apache.version’, None),
))
con.commit()
Summary:
Any reference to nasible_local.apache.name (etc) returns NULL in nasible callback function.
Please advice what I have to do, as I understand ansible_local is DICT in python, do I have to run some special functions to get access for facts in format: Main-fact-name.some-subname.some… ???
Best regards,
Marcin Praczko