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 engineer, Cloud/Kubernetes specialist, Free/Open source geek, and an author.

I believe in self CI/CD (Continuous Improvements/Development), also that "the whole is greater than the sum of its parts".

DevOps transformation, automation, data, and metrics are my preferred areas. And I like to help both businesses and people to grow.

Latest Post

🔀Merger🔀, a schemaless strategic merge plugin - Kustomize

Kustomize is a great tool. I've been using Kustomize for almost 4 years and am happy with it. However, it's ...

Popular Posts