• Stars
    star
    172
  • Rank 221,201 (Top 5 %)
  • Language
    Python
  • License
    GNU General Publi...
  • Created about 8 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Ansible dynamic inventory script for Netbox.

Netbox dynamic inventory script

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

Please note: This project is not under active development anymore, please use NetBox community Ansible modules.

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

$ ansible-netbox-inventory -h
usage: ansible-netbox-inventory [-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

More Repositories

1

kubech

Set kubectl context/namespace per shell/terminal to manage multi Kubernetes clusters at the same time.
Shell
85
star
2

devops-coding-mentorship

Helping DevOps Engineers to write more code
68
star
3

awesome-kustomize

A curated and collaborative list of awesome Kustomize resources
53
star
4

fix-common-arabic-mistakes

Libreoffice macros (Basic and Python) use Regex to fix common Arabic mistakes.
Python
26
star
5

ansible-inventory-from-ssh-config

Simple Bash and AWK script to generate Ansible inventory from SSH config file, it's really simple and assume you have "Host", "Hostname", "Port", "User" in separated lines, and valid SSH config file (there are no checks or tests done at all).
Shell
22
star
6

german-nouns-gender-analyzer

A simple script analyses 2 data-sets to find the percentage of grammatical gender for German nouns.
Python
14
star
7

consul-ssh-conf-generator

API with CLI to get hosts from Consul and format them in SSH config style.
Go
7
star
8

proccheck-telegraf-influxdb

Monitor list of processes and print their status in InfluxDB format.
Python
6
star
9

opsview-as-ansible-inventory

Python script retrieves servers list and ssh ports from Opsview via APIs, and it supports 4 kinds of output formats: Ansible dynamic inventory, Ansible static/INI-like inventory, OpenSSH config file, and pure JSON.
Python
6
star
10

docker-best-practices-workshop

Docker Best Practices Workshop hands-on
JavaScript
5
star
11

simplyubuntu.com

Files for my book "Simply Ubuntu" (Arabic).
JavaScript
4
star
12

modern-data-platform-poc

My M.Sc. dissertation: Modern Data Platform using DataOps, Kubernetes, and Cloud-Native ecosystem to build a resilient Big Data platform based on Data Lakehouse architecture which is the base for Machine Learning (MLOps) and Artificial Intelligence (AIOps).
Jupyter Notebook
4
star
13

opsview-odw-legacy-support

Simple script to install Opsview Data Warehouse (ODW) that no longer available with "Opsview Core".
Perl
3
star
14

add-host-to-opsview

Automate adding a new host with templates via Opsview API.
Python
3
star
15

kustomize-kubeconformvalidator

A plugin built around Kubeconform to validate manifests schema within Kusomize.
Go
3
star
16

intro-to-k8s-operators-demo

A pretty simple demo but beyond "hello world" for "Introduction to Kubernetes Operators" session
YAML
2
star
17

repair-partitions-table-zenity-script.sh

Simple script with Zenity GUI to backup, restore or repair partitions table.
Shell
2
star
18

nagios_bandwidth_report

Simple Nagios check script to monitor and record daily, weekly and monthly bandwidth, using vnstat.
Shell
2
star
19

aabouzaid

My GitHub Profile README
1
star
20

camunda-bpm-platform-helm

Smarty
1
star
21

kapacitor-opsgenie

A Python script runs via Kapacitor to send alerts to OpsGenie with more control.
Python
1
star
22

terraform-external-data-source-saltstack-pillar

Python script to read from SaltStack Pillar, and return the value in Terraform as external data source.
Python
1
star
23

list-ansible-inventory-groups

Ansible local module to list groups in -static- inventory using Python.
Python
1
star
24

flume-formula

SaltStack formula for Apache Flume.
HTML
1
star
25

check-nginx

Small enhancements on "check_nginx" in https and NIC binding.
Shell
1
star
26

ansible-latest-s3cmd

Ansible role to install and configure latest s3cmd version (via pip).
1
star
27

telegraf-flume-plugin

Telegraf plugin to collect Apache Flume metrics
Go
1
star
28

ansible-role-yourls

Ansible role to install Yourls, a URL shortener web app.
1
star
29

freeopensourceguide.com

Files for book "Free and OpenSource Guide" (Arabic).
JavaScript
1
star
30

fix-ubuntu-for-arabic-user

Small app fixes some common issue in Ubuntu related to Arabic
Shell
1
star