Facts and variables
Now that we have looked at the code that Jinja2 templates provide, let's understand where this data comes from, which is then embedded in the template at runtime. Data can come from either facts or variables. When it comes to a Jinja2 template, the same rules apply to the usage of facts and variables. Facts are a type of variable; the differentiating factor here is the origin of the two. Facts are automatically available and discovered at runtime, and variables are user-defined.
Automatic variables – facts
A lot of data in our systems is automatically discovered and made available to Ansible by the managed hosts during the handshake process. This data is very useful and tells us everything about that system, such as:
- The hostname, network interface, and IP address
- The system architecture
- The operating system
- The disk drives
- The processor used and amount of memory
- Whether it is a VM; if yes, is it a virtualization/cloud provider?
Tip
Facts are collected at the very...