Ansible style guide: INJECT_FACTS_AS_VARS = false
-compatible fact usage?
#18
Labels
documentation
Improvements or additions to documentation
help wanted
Extra attention is needed
question
Further information is requested
To improve consistency and compatibility with
INJECT_FACTS_AS_VARS
= false
, update the style guide to recommend usingansible_facts['<keyname>']
instead of the shorthand{{ ansible_<keyname> }}
for fact references.Current Behavior:
The shorthand
{{ ansible_<keyname> }}
is commonly used to reference facts, which depends on theINJECT_FACTS_AS_VARS
setting being enabled. However, for clarity, portability, and future-proofing playbooks, it is better to reference facts explicitly usingansible_facts['<keyname>']
.Example of the shorthand (current, not preferred):
Proposed Change:
Recommend the explicit usage of
ansible_facts
in the style guide for accessing facts. This ensures compatibility withINJECT_FACTS_AS_VARS = false
, which disables the automatic injection of facts as top-level variables.Example of the preferred method:
Rationale:
INJECT_FACTS_AS_VARS = true
ansible_facts['<keyname>']
makes it clear where the data originates.The text was updated successfully, but these errors were encountered: