From the course: Ansible for Automation Essential Training: Advanced Playbooks, Roles, and Diverse Hosts

Unlock this course with a free trial

Join today to access over 24,700 courses taught by industry experts.

Creating dynamic inventory files

Creating dynamic inventory files

- [Instructor] Thus far, all the inventories used are manually constructed, which is just fine for static or slow-changing environments. To work around this, an admin can employ something called a dynamic inventory. In short, it's a Python script that runs and generates an inventory from an external source. This source could be something as simple as a CSV file that is consumed, but more commonly, it's something like ServiceNow, VMware vCenter, AWS, or GCP. For common sources of truth, there are already existing scripts just a Google away. It's when I'm trying to do something more complex or a system less used that I have to do something custom. This example playbook uses the groups magic variable to print out hosts in the inventory. It gives me access to every group in the inventory, and in this instance, I'm asking for the contents of the all group. The real magic comes from the custom_inventory Python script. There's a lot going on in this file, but most of it's boilerplate. The…

Contents