[action_plugin] Why does set_fact overwrite a fact and my 1:1 copy set_fact2 does not?

Hi all,

I created my own action plugin, I based it of set_fact.

It works when the fact is not set already, otherwise it does not.
To be sure I did not do any mistake (cause I could not find one in my code)
I copied the whole set_fact code and called the file set_fact2.py

In the library of my ansible project the module info: library/set_fact2.py, and the action plugin into the
action_plugins/set_fact2.py

So my question: Why does the copy set_fact2 not overwrite value test? But original set_fact does? (again it is the same code, without any changes from my side)

Is there some setting for this somewhere else?

My ansible-playbook looks like

`

  • set_fact:
    test: 1

  • set_fact2:
    test: 2

  • debug:
    var: test

  • set_fact:
    test: 3

  • debug:
    var: test
    `

This is what happens:

TASK [set_fact] ********************************************************************************************************************************************************************************************************
ok: [localhost] => {
“ansible_facts”: {
“test”: 1
},
“changed”: false
}

TASK [set_fact2] *******************************************************************************************************************************************************************************************************
ok: [localhost] => {
“ansible_facts”: {
“test”: 2
},
“changed”: false
}

TASK [debug] ***********************************************************************************************************************************************************************************************************
ok: [localhost] => {
“test”: 1
}

TASK [set_fact] ********************************************************************************************************************************************************************************************************
ok: [localhost] => {
“ansible_facts”: {
“test”: 3
},
“changed”: false
}

TASK [debug] ***********************************************************************************************************************************************************************************************************
ok: [localhost] => {
“test”: 3
}

Thanks for any help.

Kind Regards
Christian

because set_fact and include_vars are 'special', the code you see is
only 1/2 of the issue, the core engine treats them specially, which
won't happen for set_fact2