Ansible Facts not persistent in Foreman

When using the module ‘set_fact’ in ansible, the callback to The Foreman seems to be working, because Immediately after running the playbook, the facts are found in The Foreman.
But it seems that running a playbook with other facts set, erases the result from the previously set facts.
It seems also that with setting more than one fact, using the module, only the last one is reported.

How should I achieve persistent facts ?

Merging things in Ansible is hard:

In other words, we know about the issue, we’re trying to fix that but the PR in ansible repo is stale and we can’t get anyone to merge it. It will probably change soon, since the callback will live in some of our repos. Right now, you can patch the callback with the version from linked PR, that should fix the problem.

1 Like

Could you give me a link to some resources how to patch the callback ?
It is a feature that would improve the use of Foreman a lot for us.
Thanks and keep up the fantastic work

You need to locate the ansible installation directory, this depends on how you install it, e.g. rpm -ql ansible would list all installed files. Then find a callback/, which is the callback that forwards facts to Foreman, e.g. rpm -ql ansible | grep callback/ Then replace it with

However, keep in mind, this will get overriden with every ansible upgrade, consider it a temporary workaround.

Hi Thank you for the instructions.
Because the patched version of the callback was complaining about the requests module being to old, I decided to upgrade foreman itself. Accidently I upgraded to Foreman 2.1.0 instead of 1.24 ?
Now when I run ansible, the callback is working again, but even with this patched version, facts are still being erased from a previous run…

Can you please double check the patch is still applied? If you did something like yum upgrade, it may have updgraded also ansible package and hence remove the patch.

Yes, I copied it again after the update.
I did a diff with the copied version to double check

I’m now trying with gather_facts set to ‘yes’

It doesn’t seem to matter if I run consecutive playbooks or set multiple facts in one playbook

Also the callback file seems to be @ /usr/lib/python2.7/site-packages/ansible/plugins/callback/ whereas before there seem to be multiple locations

I’m now also getting this error:
Task: Set a fact to show up in Foreman
422 Client Error: Unprocessable Entity

Can it be a misconfiguration that I did ?

I’m sorry, I’m here again, but I really would like this feature to work.
I’m using a workaround putting all the info I need in a dictionary set this as my last fact.
Very rarely it occurs that one of the other facts that were set in this playbook ‘survives’ and appears next to the dictionary as a fact in Foreman.

Any tips on how I can troubleshoot this issue ?
Or should I try with a fresh install ?

It’s been a few months, but to get around the error:
**[WARNING]: The requests python module is older than 2.14.0. Disabling the Foreman callback plugin.**

Replace the corresponding line that checks the requests version.

diff /tmp/ /usr/lib/python2.7/site-packages/ansible/plugins/callback/
<             if requests_version < (2, 14):
>             if requests_version < (2):

This worked for me.