Giter VIP home page Giter VIP logo

ansible-dbinventory's Introduction

ansible-dbinventory

dbinbventory is a ansible dynamic inventory script that provides an alternative to .ini file editing. It simplifies and speeds up expanding inventories (host and group management) by combining a CLI UI, JSON I/O, and sqlite storage.

curses interface

Requirements

OPTIONAL - for curses interface

Usage

Create the initial database

dbinventory.py --db-create

Creates a file named {CWD}/.dbinventory.sqlite3

You may specify the the database location with a --db-path argument ,or, through the DBINVENTORY_PATH environment variable. E.g.

dbinventory.py --db-create --db-path=/ansible/hosts.sqlite3

-- or --

export DBINVENTORY_PATH="/ansible/hosts.sqlite3" && dbinventory.py --db-create

HINT :

by default dbinventory looks for a database file named {CWD}/.{SCRIPT_NAME}.sqlite3.

This is important because it allows you to follow ansible best practices. -- keeping a unique inventory file PER ENVIRONMENT. E.g.

cp dbinventory.py {production.py,staging.py}
./staging.py --db-create --db-import staging/hosts.json
./production.py --db-create --db-import production/hosts.json

./staging.py -e
# will open management interface for hosts backed by ./staging.sqlite3

Bulk import hosts, vars, and tags from a JSON source

dbinventory.py --db-import /path/to/data.json

Atomically applies entities from a JSON file. Currently the best method for bulk management. An example file is provided in test-data/initial-data.json.

Additionally, you may export the database data in a format that can be imported:

dbinventory.py --db-export > /path/to/data.json

Manage Hosts and Groups

Hosts and Groups are managed through the JSON I/O arguments, or, a curses interface. E.g.

# spawn the management interface with --edit. requires npycurses library
dbinventory.py -e

In dbinventory, think of "tags" as ansible host groups, and "tag groups" used to taxonomize tags and coherently present them in the curses interface.

SSH Config compatible Output

You may use dbinventory to generate ssh config files as well.

db-inventory.py --ssh-config >> ~/.ssh/config
cat ~/.ssh/config
##### dbinventory hosts #####
#############################

## ACME-db1 groups: ACME, dec, mysql
Host ACME-db1
HostName 8.8.8.9
User roadrunner

## ACME-web1 groups: ACME, dec, magento, redis
Host ACME-web1
HostName 8.8.8.8
User roadrunner

## rabbit-web1 groups: bin, magento, sla
Host rabbit-web1
User bugs

## rabbit-web2 groups: magento
Host rabbit-web2
User bugs 

Sensitive Data

You may store the ssh and sudo password used to interract with a host. Their values are encrypted using an AES symmetric key -- and may only be accessed if dbinventory is called with the --db-secret flag (or the DBINVENTORY_SECRET environmental variable is set). If you do not provide a secret, these fields will not appear in results or be editable in forms.

db-inventory.py --add-host <Host> --db-secret="super secret password"

alternatively, use a persistent environment variable

export DBINVENTORY_SECRET="super secret password"
db-inventory.py --host <Host>

NOTE: The first time dbinventory accesses a database using a secret key, a known value is encoded. Subsequent calls decrypt and test the known value for a match. If your secret does not match the secret stored in the database, dbinventory will complain and exit. This is meant to provent a operator misspellings of the secret, which could result in unretrievable data.

Development

TODO:

  • finish tag + group editing
  • fix height issue
  • allow reselection of edited host/tag

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.