Configuration

The configuration is comprised of a set of sections and parameters for those sections. You can set the configuration programmatically using nornir by passing a dictionary of options for each section, by using a YAML file, by setting the corresponding environment variables or by a combination of the three. The order of preference from less to more preferred is “configuration file” -> “env variable” -> “code”.

An example using InitNornir would be:

  1. nr = InitNornir(
  2. runner={"plugin": "threaded", "options": {"num_workers": 20}},
  3. logging={"log_file": "mylogs", "level": "DEBUG"}
  4. )

A similar example using a yaml file:

  1. ---
  2. inventory:
  3. plugin: SimpleInventory
  4. options:
  5. host_file: "advanced_filtering/inventory/hosts.yaml"
  6. group_file: "advanced_filtering/inventory/groups.yaml"
  7. runner:
  8. plugin: threaded
  9. options:
  10. num_workers: 20

Logging

By default, Nornir automatically configures logging when InitNornir is called. Logging configuration can be modified and available options are described in the section below. If you want to use Python logging module to configure logging, make sure to set logging.enabled parameter to False in order to avoid potential issues.

In some situations Nornir will detect previous logging configuration and will emit nornir.core.exceptions.ConflictingConfigurationWarning

Next, you can find each section and their corresponding options.

core

raise_on_error

DescriptionIf set to True, (nornir.core.Nornir.run) method of will raise exception nornir.core.exceptions.NornirExecutionError if at least a host failed
Typeboolean
DefaultFalse
RequiredFalse
Environment VariableNORNIR_CORE_RAISE_ON_ERROR

runner

plugin

DescriptionPlugin to use as Runner. Must be registered
Typestring
DefaultThreaded
RequiredFalse
Environment VariableNORNIR_RUNNER_PLUGIN

options

Descriptionkwargs to pass to the plugin
Typeobject
Default{}
RequiredFalse
Environment VariableNORNIR_RUNNER_OPTIONS

inventory

plugin

DescriptionPlugin to use. Must be registered
Typestring
DefaultSimpleInventory
RequiredFalse
Environment VariableNORNIR_INVENTORY_PLUGIN

options

Descriptionkwargs to pass to the plugin
Typeobject
Default{}
RequiredFalse
Environment VariableNORNIR_INVENTORY_OPTIONS

transform_function

DescriptionPlugin to use. Must be registered
Typestring
Default 
RequiredFalse
Environment VariableNORNIR_INVENTORY_TRANSFORM_FUNCTION

transform_function_options

Descriptionkwargs to pass to the transform_function
Typeobject
Default{}
RequiredFalse
Environment VariableNORNIR_INVENTORY_TRANSFORM_FUNCTION_OPTIONS

ssh

config_file

DescriptionPath to ssh configuration file
Typestring
Default~/.ssh/config
RequiredFalse
Environment VariableNORNIR_SSH_CONFIG_FILE

logging

enabled

DescriptionWhether to configure logging or not
Typeboolean
DefaultNone
RequiredFalse
Environment VariableNORNIR_LOGGING_ENABLED

level

DescriptionLogging level
Typestring
DefaultINFO
RequiredFalse
Environment VariableNORNIR_LOGGING_LEVEL

log_file

DescriptionLogging file
Typestring
Defaultnornir.log
RequiredFalse
Environment VariableNORNIR_LOGGING_LOG_FILE

format

DescriptionLogging format
Typestring
Default%(asctime)s - %(name)12s - %(levelname)8s - %(funcName)10s() - %(message)s
RequiredFalse
Environment VariableNORNIR_LOGGING_FORMAT

to_console

DescriptionWhether to log to console or not
Typeboolean
DefaultFalse
RequiredFalse
Environment VariableNORNIR_LOGGING_TO_CONSOLE

loggers

DescriptionLoggers to configure
Typearray
Default[‘nornir’]
RequiredFalse
Environment VariableNORNIR_LOGGING_LOGGERS

user_defined

You can set any <k, v> pair you want here and you will have it available under your configuration object, i.e. nr.config.user_defined.my_app_option.