The documentation covers this:

https://docs.ansible.com/ansible/latest/user_guide/playbooks_variables.html#variable-precedence-where-should-i-put-a-variable

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.

On Tue, Nov 2, 2021 at 9:39 AM [email protected] <[email protected]>
wrote:

> 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
>
> On Tuesday, November 2, 2021 at 9:59:58 AM UTC-4 [email protected]
> wrote:
>
>> 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
>> https://pastebin.com/zrh2MLKZ - ansible results
>>
>> 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
>>
>> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/fd8170c9-dc56-4834-9867-d82fda8df6f2n%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/fd8170c9-dc56-4834-9867-d82fda8df6f2n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>


-- 
Matt Martz
@sivel
sivel.net

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAD8N0v8kBkx8G1f3OYEd5hcR04kQ8WHkd0GKMwuzObx5Pu8rOQ%40mail.gmail.com.

Reply via email to