From the course: Ansible: From Basics to Guru by Pearson

Unlock this course with a free trial

Join today to access over 25,200 courses taught by industry experts.

Using magic variables

Using magic variables

In this video, we'll discuss magic variables, as they call them. So what is this? Well, really, magic variables are system variables. They are built-in and they cannot be used for anything else, and they have highest priority. Some examples are host vars. Host vars is a dictionary that contains all the variables that apply to a specific host. There's Inventory Hostname, which is the inventory name of the current host. There's Inventory Hostname Short, which is the short host inventory name. Or an important one is Groups, which refers to all hosts in an inventory and the groups that these hosts belong to. Or Group Names, which lists the groups that a current host is a part of. Ansible CheckMode is a boolean that indicates if play is in check mode and AnsiblePlayBatch is giving the active hosts in the current play. And finally, there's also AnsiblePlayHosts, which is doing the same, and AnsibleVersion, which is for the current AnsibleVersion. The only thing that you should know about…

Contents