action_plugins and ansible_facts

27 views
Skip to first unread message

jo...@technoplaza.net

unread,
Nov 2, 2021, 9:59:58 AM11/2/21
to Ansible Project
I'm using action plugins to collect data from an internal API. We've been setting the "ansible_facts" key of the results dictionary to return values. Most of the time, this seems to work as if we had called set_fact. But if we use set_fact on the same variable, ansible_facts doesn't overwrite the value. Is this expected behavior?

https://pastebin.com/553q7PNH -- playbook example
https://pastebin.com/aeAWyZhp -- set_contact_id.py action_plugin

From the results, you can see that the contact_id is initially unset, so the display is 0.
Then the action_plugin uses ansible_facts to set it to 15731, which is displayed.
Then I call set_fact, which changes the value to 22124.
Finally, I try to update the value by calling the action_plugin again. This time, I see ansible_facts has the contact_id value set to 11131, but when I display it, I still see 22124. The ansible_facts from the action plugin did not overwrite the value. Is this expected behavior, or am I doing something wrong?

Thanks.

--John

jo...@technoplaza.net

unread,
Nov 2, 2021, 10:39:15 AM11/2/21
to Ansible Project
I feel like this has to be a bug of some kind. I can use the exact code for the set_fact action plugin and I get no difference in the results. It certainly looks like I am doing exactly what ansible is doing internally, but getting different results.

--John

Matt Martz

unread,
Nov 2, 2021, 10:47:34 AM11/2/21
to ansible...@googlegroups.com
The documentation covers this:


1. `ansible_facts` are `host facts` which are #11
2. `set_fact` (without cacheable=yes) is #19

So `set_fact` via default use always wins.

--
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 ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/fd8170c9-dc56-4834-9867-d82fda8df6f2n%40googlegroups.com.


--
Matt Martz
@sivel
sivel.net

jo...@technoplaza.net

unread,
Nov 2, 2021, 10:59:03 AM11/2/21
to Ansible Project
Okay. I didn't put together that "ansible_facts" are host facts. Thanks.

--John
Reply all
Reply to author
Forward
0 new messages