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 smart inventories

Using smart inventories

Let's talk about another inventory feature, which is Smart Inventory. So what is Smart Inventory? Well, Smart Inventory is dynamically created from other inventory sources by using a filter. So Smart Inventory allows you to search for specific facts, basically, that are discovered on hosts and create an inventory based on that. Smart Inventory uses FactCache, so you will have to create a job template with the useFactCache option and run this template periodically. Now in Smart Inventory, there's a filter. The filter may look like AnsibleFacts.AnsibleDistribution colon RedHat, for instance. That allows you to create an inventory that matches any property. In this filter, you should notice that pre-Ansible 2.5 notation is used. So you cannot use the modern notation with the square brackets, that means. And AnsibleFacts indicates the filter applies to AnsibleFacts and not a host name or anything else. So the notation is AnsibleFacts.AnsibleDistribution. And this is what is surprising…

Contents