Interview Prep/Ansible/Variables, Facts and Precedence

What is the difference between `ansible_facts['x']` and the older `ansible_x` variables?

IntermediateConceptVariables, Facts and Precedence
Answer

Facts are available in two forms. ansible_facts['distribution'] is the namespaced form and is always present. The injected form ansible_distribution was created for backwards compatibility and is controlled by inject_facts_as_vars (default true, planned to change to false in a future release).

Use ansible_facts[...] in new code. The injected variables also have a higher precedence than inventory vars, which can cause confusing collisions.

All Ansible questions Roadmap: Ansible

More on Variables, Facts and Precedence