-
Notifications
You must be signed in to change notification settings - Fork 1
Description
To improve consistency and compatibility with INJECT_FACTS_AS_VARS = false, update the style guide to recommend using ansible_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 the INJECT_FACTS_AS_VARS setting being enabled. However, for clarity, portability, and future-proofing playbooks, it is better to reference facts explicitly using ansible_facts['<keyname>'].
Example of the shorthand (current, not preferred):
- ansible.builtin.debug:
msg: "{{ ansible_distribution }}" Proposed Change:
Recommend the explicit usage of ansible_facts in the style guide for accessing facts. This ensures compatibility with INJECT_FACTS_AS_VARS = false, which disables the automatic injection of facts as top-level variables.
Example of the preferred method:
- ansible.builtin.debug:
msg: "{{ ansible_facts['distribution'] }}" Rationale:
- Compatibility: The shorthand relies on behavior tied to
INJECT_FACTS_AS_VARS = true - Explicit and readable: Using
ansible_facts['<keyname>']makes it clear where the data originates.