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, I'm a passionate Tech Lead DevOps Engineer. 👋

I specialize in Cloud-Native and Kubernetes. I'm also a Free/Open source geek and book author. My favorite topics are DevOps transformation, DevSecOps, automation, data, and metrics.

More about me ➡️

Contact Me

Name

Email *

Message *

Start Your DevOps Engineer Journey!

Start Your DevOps Engineer Journey!
Start your DevOps career for free the Agile way in 2024 with the Dynamic DevOps Roadmap ⭐

Latest Post

Bootstrap Cloud-Native bootstrappers like Crossplane with K3d - Automation

I created a logo for the Crossplane Bootstrapper because all good projects deserve a logo. 😁 TL;DR ...

Popular Posts

Blog Archive