Skip to main content

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.



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:

  1. sql_connection: SQLAlchemy connection string
    Format: {driver}://[user]:[password]@{DBSERVER}/{DATABASE}
    SQLite example:
    sqlite:///somedb.db
    MSSQL example with domain user authentication:
    mssql+pymssql://ACME\\dbuser:verysecret@DBSRV1/INFRA
  2. 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!
  3. groups_query: Select statement which returns groups inventory elements.
    Same requirements apply as for the hosts_query.
  4. groups_file: path to a YAML file containing group definitions. Format is that same as used by SimpleInventory
    This parameter is ignored when groups_query or groups are specified!
    Using this parameter requires group assignments outside of this plugin! Check docs!
  5. 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!
  6. defaults: This is a dictionary which contains inventory elements. These will be applied to hosts.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nornir_sql-0.0.4.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nornir_sql-0.0.4-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file nornir_sql-0.0.4.tar.gz.

File metadata

  • Download URL: nornir_sql-0.0.4.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for nornir_sql-0.0.4.tar.gz
Algorithm Hash digest
SHA256 c8691e3788d770eb7095e4766d773220df6c0aaf0b4880919896c4a39558ae4b
MD5 2259639e2ab85c43a46ca93bade0abf6
BLAKE2b-256 cb9788390e37759924976345b232e78c1fc7c2a094787c5802a7a3d42de2e8e0

See more details on using hashes here.

File details

Details for the file nornir_sql-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: nornir_sql-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 5.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for nornir_sql-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 0c4dd630d7dd4bfe96cbceb8c232aa5e0b56d805d2e1e9c9007451ca05ddf800
MD5 fc6ab5ad990d2e4fd6dd6b7121796bae
BLAKE2b-256 fdfea3614bd830142e8ea06bee04da4636ed6719624fd3f490fd5501035bd003

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page