Simple inventory plugin

To demonstrate developing an inventory plugin, we'll create one that simply prints the same host data we've been using in our mastery-hosts file. Integrating with a custom asset management system or an infrastructure provider is a bit beyond the scope of this book, so we'll simply code the systems into the plugin itself. We'll write our inventory plugin to a file in the top level of our project root named mastery-inventory.py and make it executable. We'll use Python for this file, to handle execution arguments and JSON formatting with ease:

  1. First, we'll need to add a sha-bang line to indicate that this script is to be executed with Python:
#!/usr/bin/env python 
# 
  1. Next, we'll need to import a couple of Python modules ...

Get Mastering Ansible - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.