nornir.core.__init__

class nornir.core.__init__.Nornir(inventory: Inventory, config: Config | None = None, data: GlobalState | None = None, processors: Processors | None = None, runner: RunnerPlugin | None = None)

This is the main object to work with. It contains the inventory and it serves as task dispatcher.

Parameters:
inventory

Inventory to work with

Type:

nornir.core.inventory.Inventory

data

shared data amongst different iterations of nornir

Type:

nornir.core.GlobalState

dry_run

Whether if we are testing the changes or not

Type:

bool

config

Configuration parameters

Type:

nornir.core.configuration.Config

close_connections(on_good: bool = True, on_failed: bool = False) None
dict() Dict[str, Any]

Return a dictionary representing the object.

filter(*args: Any, **kwargs: Any) Nornir

See nornir.core.inventory.Inventory.filter()

Returns:

A new object with same configuration as self but filtered inventory.

Return type:

Nornir

classmethod get_validators() Generator[Callable[[Nornir], Nornir], None, None]
run(task: Callable[[...], Any], raise_on_error: bool | None = None, on_good: bool = True, on_failed: bool = False, name: str | None = None, **kwargs: Any) AggregatedResult

Run task over all the hosts in the inventory.

Parameters:
  • task (callable) – function or callable that will be run against each device in the inventory

  • raise_on_error (bool) – Override raise_on_error behavior

  • on_good (bool) – Whether to run or not this task on hosts marked as good

  • on_failed (bool) – Whether to run or not this task on hosts marked as failed

  • **kwargs – additional argument to pass to task when calling it

Raises:

nornir.core.exceptions.NornirExecutionError – if at least a task fails and self.config.core.raise_on_error is set to True

Returns:

results of each execution

Return type:

nornir.core.task.AggregatedResult

property runner: RunnerPlugin
classmethod validate(v: Nornir) Nornir
with_processors(processors: List[Processor]) Nornir

Given a list of Processor objects return a copy of the nornir object with the processors assigned to the copy. The original object is left unmodified.

with_runner(runner: RunnerPlugin) Nornir

Given a runner return a copy of the nornir object with the runner assigned to the copy. The original object is left unmodified.