O'Reilly logo

Ansible Configuration Management - Second Edition by Daniel Hall

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Extra variables

You may have seen in our template example in the previous chapter that we used a variable named group_names. This is one of the magic variables that are provided by Ansible itself. At the time of writing, there are seven such variables, which are described in the upcoming sections.

The hostvars variable

The hostvars variable allows you to retrieve variables of all the hosts that the current play has dealt with. If the setup module hasn't yet been run on that managed host in the current play, only its variables will be available. You can access it like you would access other complex variables, such as ${hostvars.hostname.fact}, so to get the Linux distribution running on a server named ns1, it would be ${hostvars.ns1.ansible_distribution} ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required