Plugin configurationΒΆ
The plugin takes options in order to configure what DB to use, what queries it should run to construct the inventory. These options are the following:
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/INFRAhosts_query: Select statement which returns hosts inventory elements.The select must return at minimum thenamefield!Field names must match the expected Nornir inventory elements!Thedataelements are expected indata.[element]format. Quotation is needed!Ifgroupsare returned, the followinggroups_queryalso has to be specified!groups_query: Select statement which returns groups inventory elements.Same requirements apply as for thehosts_query.groups_file: path to a YAML file containing group definitions. Format is that same as used bySimpleInventoryThis parameter is ignored whengroups_queryorgroupsare 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 usinggroups_file!Ignored whengroups_queryis 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.
At minimum, sql_connection and hosts_query must be specified. Other options are optional.
Very minimal inventory setup:
from nornir.core import InitNornir
inventory = {
"plugin": "SQLInventory",
"options": {
"sql_connection": "sqlite:///asset.db",
"hosts_query": "select name, hostname from hosts"
}
}
nr = InitNornir(inventory=inventory)