nornir.core.task
- class nornir.core.task.AggregatedResult(name: str, **kwargs: MultiResult)
Dict-like object that aggregates the results for all devices.
You can access each individual result by doing
my_aggr_result["hostname_of_device"].- property failed: bool
If
Trueat least a host failed.
- property failed_hosts: dict[str, nornir.core.task.MultiResult]
Hosts that failed during the execution of the task.
- raise_on_error() None
Raise an exception if at least a task failed.
- Raises:
nornir.core.exceptions.NornirExecutionError – When at least a task failed
- class nornir.core.task.MultiResult(name: str)
List-like object with the results of all the subtasks for a particular device/task.
- property changed: bool
If
Trueat least a task changed the system.
- property failed: bool
If
Trueat least a task failed.
- raise_on_error() None
Raise an exception if at least a task failed.
- Raises:
nornir.core.exceptions.NornirExecutionError – When at least a task failed
- class nornir.core.task.Result(host: Host | None, result: Any = None, changed: bool = False, diff: str = '', failed: bool = False, exception: BaseException | None = None, severity_level: int = 20, **kwargs: Any)
Result of running individual tasks.
- Parameters:
changed (bool) –
Trueif the task is changing the systemdiff (obj) – Diff between state of the system before/after running this task
result (obj) – Result of the task execution, see task’s documentation for details
host (
nornir.core.inventory.Host) – Reference to the host that lead to this resultfailed (bool) – Whether the execution failed or not
severity_level (logging.LEVEL) – Severity level associated to the result of the excecution
exception (Exception) – uncaught exception thrown during the exection of the task (if any)
- changed
Trueif the task is changing the system- Type:
bool
- diff
Diff between state of the system before/after running this task
- Type:
obj
- result
Result of the task execution, see task’s documentation for details
- Type:
obj
- host
Reference to the host that lead ot this result
- failed
Whether the execution failed or not
- Type:
bool
- severity_level
Severity level associated to the result of the excecution
- Type:
logging.LEVEL
- exception
uncaught exception thrown during the exection of the task (if any)
- Type:
Exception
- class nornir.core.task.Task(task: Callable[..., Any], nornir: Nornir, global_dry_run: bool, processors: Processors, name: str | None = None, severity_level: int = 20, parent_task: Task | None = None, **kwargs: str)
Wrapper around a function that has to be run against multiple devices.
You won’t probably have to deal with this class yourself as
nornir.core.Nornir.run()will create it automatically.- Parameters:
task (callable) – function or callable we will be calling
name (
string) – name of task, defaults totask.__name__severity_level (logging.LEVEL) – Severity level associated to the task
**kwargs – Parameters that will be passed to the
task
- task
function or callable we will be calling
- Type:
callable
- name
name of task, defaults to
task.__name__- Type:
string
- params
Parameters that will be passed to the
task.
- self.results
Intermediate results
- host
Host we are operating with. Populated right before calling the
task
- nornir
Populated right before calling the
task- Type:
nornir.core.Nornir
- severity_level
Severity level associated to the task
- Type:
logging.LEVEL
- is_dry_run(override: bool | None = None) bool
Return whether the current task is a dry run or not.
- Returns:
Trueif the task is a dry run,Falseotherwise.
- run(task: Callable[..., Any], **kwargs: Any) MultiResult
Call a task from within a task.
For instance:
def grouped_tasks(task): task.run(my_first_task) task.run(my_second_task) nornir.run(grouped_tasks)
This method will ensure the subtask is run only for the host in the current thread.
- Returns:
Results of the subtask and its own subtasks
- Return type:
- Raises:
Exception – the
hostattribute has not been set, which happens when calling this from outside a nested tasknornir.core.exceptions.NornirSubTaskError – the subtask failed
- start(host: Host) MultiResult
Run the task for the given host.
- Parameters:
host (
nornir.core.inventory.Host) – Host we are operating with. Populated right before calling thetask- Returns:
Results of the task and its subtasks
- Return type: