nornir_sql
Project description
Welcome to Nornir SQL inventory plugin!
If your device inventory is spread across SQL database tables and you would like to use it as Nornir inventory, you may consider looking on this project.
Documentation: https://viktorkertesz.github.io/nornir_sql
Source code: https://github.com/viktorkertesz/nornir_sql
Installation
Install from pypi
pip install nornir-sql
Install from GitHUB
pip install git+https://github.com/viktorkertesz/nornir_sql.git
Simple example
from nornir import InitNornir
host_query = """\
SELECT ciname AS name, ip AS hostname, region AS 'data.region'
FROM host_table
WHERE status='deployed'
"""
inventory = {
"plugin": "SQLInventory",
"options": {
"sql_connection": "sqlite:///inventory.db",
"hosts_query": hosts_query,
}
}
nr = InitNornir(inventory=inventory)
print(nr.inventory.hosts['FW1']['region'])
Configuration
This plugin is based on SQLAlchemy and supports all databases that SQLAlchemy does.
These configuration options can be used:
- sql_connection: SQLAlchemy connection stringFormat: {driver}://[user]:[password]@{DBSERVER}/{DATABASE}SQLite example:sqlite:///somedb.dbMSSQL example with domain user authentication:mssql+pymssql://ACME\\dbuser:verysecret@DBSRV1/INFRA
- hosts_query: Select statement which returns hosts inventory elements.The select must return at minimum the name field!Field names must match the expected Nornir inventory elements!The data elements are expected in data.[element] format. Quotation is needed!If groups are returned, the following groups_query also has to be specified!
- groups_query: Select statement which returns groups inventory elements.Same requirements apply as for the hosts_query.
- groups_file: path to a YAML file containing group definitions. Format is that same as used by SimpleInventoryThis parameter is ignored when groups_query or groups are specified!Using this parameter requires group assignments outside of this plugin! Check docs!
- groups: group definition as dict. Same restrictions and features apply as by using groups_file!Ignored when groups_query is specified!Using this parameter requires group assignments outside of this plugin! Check docs!
- defaults: This is a dictionary which contains inventory elements. These will be applied to hosts.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file nornir_sql-0.0.4.post1.tar.gz
.
File metadata
- Download URL: nornir_sql-0.0.4.post1.tar.gz
- Upload date:
- Size: 5.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b299372baee7f972beacd190a21a9e9a8d3c3b61cc7fff24435f0130895b784e |
|
MD5 | 13ba462c09a01cc15dedb5228d9089ac |
|
BLAKE2b-256 | 817a8fa07c6a95766e0c8b54682b4836687091072b3c738bba3088a1fb6e827b |
File details
Details for the file nornir_sql-0.0.4.post1-py3-none-any.whl
.
File metadata
- Download URL: nornir_sql-0.0.4.post1-py3-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6c82fe5daaa60bdf0b6a99a9605c07b114214d26d8af2ab12028ce1b2d7f3a03 |
|
MD5 | 65cd2001bc92153e12468cd280936e3a |
|
BLAKE2b-256 | 1ce2b273cfcd279bdb4aded3aa1c7870c085e1d3fcc68aaa207edbb3de4a7d40 |