Host-Level Variables
Consider an inventory file where the DNS server is specified only for the hostweb2:
dns_server variable for all hosts results in the variable being defined only for web2:

Play-Level Variables
Next, consider a scenario where a variable is defined within a play. In the following playbook, the variablentp_server is defined only in the first play, making it accessible there but not in the second play:
Global Variables
Global (or extra) variables are available throughout the entire execution of a playbook. For instance, if you run the playbook with an extra variable like so:ntp_server variable, producing the following output:
Conclusion
Understanding variable scopes—host, play, and global—is essential for managing configurations and troubleshooting within Ansible playbooks. Each scope offers a level of variable visibility that can be strategically utilized to create efficient and modular playbooks.For further details on variable precedence and advanced usage, consult the Ansible Documentation.