Skip to main content

PyPI Version Python Version Build Status Codacy Badge Code Health Coverage Status

ToC

Intro

This is a Netbox dynamic inventory script for Ansible. Netbox is 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”.

You can group servers as you want and based on what you have in Netbox, you can select fields as groups or as vars for hosts. And you can use default fields or custom fields.

Compatibility

The script tested with netbox = v1.6 and netbox = v2.0.4, but most probably it will work with all netbox v1.0 and above.

Grouping

Servers could be grouped by any section in Netbox. e.g. you can group hosts by “site, “rack”, “role”, “platform”, or any other section in Netbox. Please remember: For grouping, API names should be used not UI names.

So if you have a “site” called “US-East”, in Ansible you will get a hosts group is called “US-East” has all hosts in that site.

If that section is a default section you need to put it under group_by.default if it’s a custom section (custom fields), then put it under group_by.custom.

Here is an example how servers will be grouped based on their platform.

group_by:
   default:
       - platform

So if you have “Ubuntu” and “CentOS” as platforms in Netbox, you will have 2 groups of servers that using that systems.

Hosts variables

Netbox sections could be used as variables for hosts! e.g. you could use the IP of the host in Netbox as ansible_ssh_host, or use a custom field as well.

There are 3 sections here, first type is IP, second one is General, and finally Custom.

Variables are defined as Key: Value. The key is what will be in Ansible and value comes from Netbox.

hosts_vars:
    ip:
        ansible_ssh_host: primary_ip

Here primary_ip will be used as value for ansible_ssh_host.

Options

$ netbox.py -h
usage: netbox.py [-h] [-c CONFIG_FILE] [--list] [--host HOST]

optional arguments:
  -h, --help            show this help message and exit
  -c CONFIG_FILE, --config-file CONFIG_FILE
                        Path for script's configuration. Also
                        "NETBOX_CONFIG_FILE" could be used as env var to set
                        conf file path. (default: netbox.yml)

  --list                Print all hosts with vars as Ansible dynamic inventory
                        syntax. (default: False)
  --host HOST           Print specific host vars as Ansible dynamic inventory
                        syntax. (default: None)

You can also set config file path through environment variable NETBOX_CONFIG_FILE.

Usage

$ ansible all -i netbox.py -m ping

Release files for ansible-netbox-inventory 1.0.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ansible-netbox-inventory 1.0.9
File Size Uploaded
ansible-netbox-inventory-1.0.9.tar.gz 27.8 kB Details

Release files / ansible-netbox-inventory-1.0.9.tar.gz

Download URL ansible-netbox-inventory-1.0.9.tar.gz
Size 27.8 kB
Tags Source
SHA-256 checksum
How to use checksums
c87fec954783abf6fa47c04666238ec2a6de898b998cacf560883f5aff7db267
BLAKE2b-256 checksum
How to use checksums
b3043e83f3c64e46a93ce415950db5a67565dd6298bcac42c6a1bb91dd3d1e0b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

1.0.9 This release

1 release file

1.0.8

1 release file

1.0.7

1 release file

1.0.6

1 release file

1.0.5

1 release file

1.0.4

1 release file

1.0.3

1 release file

1.0.2

1 release file

1.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page