O'Reilly logo

Ansible Configuration Management 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 called 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, described in the following sections.

The hostvars variable

hostvars allows you to retrieve variables about all the hosts that the current play has dealt with. If the setup module hasn't yet been run on that 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}. The following example ...

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