29/10/2017

Netbox dynamic inventory script for Ansible - Python.

I use Ansible however and whenever I have a chance to do, because Ansible rocks! However nowadays I don't use Ansible as a main configuration management tool at work (but SaltStack).

Ansible's "Dynamic inventory" is one of nice features, where you can use an external service as inventory for Ansible instead the basic text-based ini file.

So you can use AWS EC2 as inventory of your hosts, or maybe OpenStack, or whatever ... you actually can use any source inventory for Ansible, and you able to write your own "External Inventory Script".

I also loved "Netbox" from DigitalOcean network engineering team! It's an IP address management (IPAM) and data center infrastructure management (DCIM) tool. It's nice, modern, and has good APIs ... so it's a pretty nice option to serve as a "Source of Truth".

Netbox is really helpful especially when you are working with a hybrid could! So I decided to write an Ansible external inventory script to get use of it.

Developing dynamic inventory sources for Ansible is pretty easy! The script conventions are straightforward and Ansible doesn't care about language of script, JSON output that's all that matters (but of course if you want to push it to the upstream, it should be Python).

On the other hand I played with a lot of new stuff here ... PyPi packaging, writing unit test with pytest, setup.py file, some CI tricks, and some Pythonic methods here and there.

More information about this inventory module are in its main repo:
Netbox dynamic inventory script.

Powered by Blogger.

Hello, my name is Ahmed AbouZaid and this is my "lite" technical blog!

I'm a passionate DevOps, Linux system administrator, RedHat Certified Engineer (RHCE), AWS SysOps/Solutions Architect, Free/Open source geek, author, interested in environment, calligraphy, and I believe that “Details Matter”!

Automation, data, and metrics are my preferred areas. I have a built-in monitoring chip, and too lazy to do anything manually :D

Popular Posts