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 preferred to more preferred is “env variable” -> “configuration file” -> “code”.
An example using InitNornir
would be:
nr = InitNornir(
runner={"plugin": "threaded", "options": {"num_workers": 20}},
logging={"log_file": "mylogs", "level": "DEBUG"}
)
A similar example using a yaml
file:
---
inventory:
plugin: SimpleInventory
options:
host_file: "advanced_filtering/inventory/hosts.yaml"
group_file: "advanced_filtering/inventory/groups.yaml"
runner:
plugin: threaded
options:
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
Description | If set to |
Type |
|
Default |
|
Required |
|
Environment Variable |
|
runner
plugin
Description | Plugin to use as Runner. Must be registered |
Type |
|
Default |
|
Required |
|
Environment Variable |
|
options
Description | kwargs to pass to the plugin |
Type |
|
Default |
|
Required |
|
Environment Variable |
|
inventory
plugin
Description | Plugin to use. Must be registered |
Type |
|
Default |
|
Required |
|
Environment Variable |
|
options
Description | kwargs to pass to the plugin |
Type |
|
Default |
|
Required |
|
Environment Variable |
|
transform_function
Description | Plugin to use. Must be registered |
Type |
|
Default | |
Required |
|
Environment Variable |
|
transform_function_options
Description | kwargs to pass to the transform_function |
Type |
|
Default |
|
Required |
|
Environment Variable |
|
ssh
config_file
Description | Path to ssh configuration file |
Type |
|
Default |
|
Required |
|
Environment Variable |
|
logging
enabled
Description | Whether to configure logging or not |
Type |
|
Default |
|
Required |
|
Environment Variable |
|
level
Description | Logging level |
Type |
|
Default |
|
Required |
|
Environment Variable |
|
log_file
Description | Logging file |
Type |
|
Default |
|
Required |
|
Environment Variable |
|
format
Description | Logging format |
Type |
|
Default |
|
Required |
|
Environment Variable |
|
to_console
Description | Whether to log to console or not |
Type |
|
Default |
|
Required |
|
Environment Variable |
|
loggers
Description | Loggers to configure |
Type |
|
Default |
|
Required |
|
Environment Variable |
|
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
.