Coder Social home page Coder Social logo

lupo / netbox-as-ansible-inventory Goto Github PK

View Code? Open in Web Editor NEW

This project forked from aabouzaid/netbox-as-ansible-inventory

0.0 1.0 0.0 155 KB

Ansible dynamic inventory script for Netbox.

License: GNU General Public License v3.0

Python 100.00%

netbox-as-ansible-inventory's Introduction

Netbox dynamic inventory script

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

$ 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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.