Inventory class

nornir_sql.plugins.inventory.sql

class nornir_sql.plugins.inventory.sql.SQLInventory(sql_connection, hosts_query, groups_query='', groups_file=None, groups=None, defaults=None)[source]

Bases: object

SQLInventory implements SQL inventory plugin for Nornir

__init__(sql_connection, hosts_query, groups_query='', groups_file=None, groups=None, defaults=None)[source]

Setup SQLInventory parameters

The SQL queries’ fields must stick to the naming convention as follows:

  1. name: The device name in the inventory
  2. hostname: Device’s hostname/fqdn/ip which is accessible
  3. port: Port on the device is accessible
  4. username: Username on the device
  5. password: Password on the device
  6. platform: Platform to use with the connection
  7. data.extra1: Will be put to data with the name of extra1
  8. groups: Coma separated group names for this host
  9. connection_options: JSON formatted connection_options string
Parameters
  • sql_connection (str) – SQL connection string. E.g.: ‘mssql+pymssql://@SERVERNAME/DBNAME’

  • hosts_query (str) – Query string for getting hosts. All fields must be named as above!

  • groups_query (str) – Query string for getting groups. All fields must be named as above!

  • groups_file (str) – YAML file path to group definition file. Ignored when groups_query or groups are specified!

  • groups (dict) – group definition as dict. Ignored when groups_query is specified!

  • defaults (dict) – dict of default values.

load()[source]

Load inventory from SQL server

Return type

nornir.core.inventory.Inventory