suggestions for additions to set_fact's documentation

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

My mistake, re-reading it I find: “Registered variables are valid on the host the remainder of the playbook run, which is the same as the lifetime of “facts” in Ansible. Effectively registered variables are just like facts.” However, the lifetime of “facts” is not defined. Maybe it should be? As I understand it “facts” in the sense of system attributes are persistent between runs, but Ansibles’ internal store of collected “facts” endure for the play (or playbook?), but not between runs. The difference is muddied since (also, as I understand it) the internal “facts” data structure, or some portion of it, gets re-created at the start of each play by the ‘setup’ module. N

Hi,

so far facts and registered variables are preserved only thru playbook. Do not be confused by “several plays” - one playbook may and have several plays every so often.

David