Hello,
I’m looking into using set_fact module for something, but the documentation is very brief and leaves me with various unanswered questions. My attempts to peek into the source code don’t answer these - the source of set_fact.py seems rather minimal too, and doesn’t enlighten me at all.
Here is what I am wondering. Of course I could probably determine the answers to these questions by experiment, but I’m sure the author of the module might be able to clarify these things faster and more definitively than I could, and the modules’ documentation would ideally contain the answers (or references to them).
-
Can I set namespaced facts? i.e. some.thing.with.periods
-
If so, can I create list elements? i.e. something.a_list.3 ? If so, what would elements 0, 1, and 2 become?
-
Can I set complex values? i.e. assign a datastructure like { x: 1, y: 2 } to some variable?
-
Can I change existing facts? (Both ones it has set and ones set elsewhere.) Delete them? If not, what happens if I try?
-
Presumably all facts it sets are accessible in the hostvars[inventory_hostname] namespace? (Since these are facts, this is implied but not explicit, and I wonder if they might be in their own namespace to avoid tangling with existing facts.)
-
Can the phrase “survive between plays” be clarified? This could mean merely that the facts endure to the end of the execution of a playbook, but I would have been surprised if they didn’t, and the possibility that they might not makes me wonder if registered variables and those set by modules return values don’t. The docs don’t say anything about a registered variable’s lifespan: http://docs.ansible.com/playbooks_variables.html.
I’m hoping set_fact facts are thereby meant to be more permanent, i.e. between playbook runs like traditional facts (which would imply some sort of persistence, perhaps to /etc/ansible/facts.d, although I see those facts are restricted to an ansible_local namespace).
Thanks
N