nornir.core.task

class nornir.core.task.AggregatedResult(name: str, **kwargs)

It basically is a dict-like object that aggregates the results for all devices. You can access each individual result by doing my_aggr_result["hostname_of_device"].

failed

If True at least a host failed.

failed_hosts

Hosts that failed during the execution of the task.

raise_on_error() → None
Raises:nornir.core.exceptions.NornirExecutionError – When at least a task failed
class nornir.core.task.MultiResult(name: str)

It is basically is a list-like object that gives you access to the results of all subtasks for a particular device/task.

changed

If True at least a task changed the system.

failed

If True at least a task failed.

raise_on_error() → None
Raises:nornir.core.exceptions.NornirExecutionError – When at least a task failed
class nornir.core.task.Result(host: Optional[Host], result: Any = None, changed: bool = False, diff: str = '', failed: bool = False, exception: Optional[BaseException] = None, severity_level: int = 20, **kwargs)

Result of running individual tasks.

Parameters:
  • changed (bool) – True if the task is changing the system
  • diff (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 ot this result
  • failed (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

True if 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

Type:nornir.core.inventory.Host
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, severity_level: int = 20, parent_task: Optional[Task] = None, **kwargs)

A task is basically a 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 to task.__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

Type:nornir.core.task.MultiResult
host

Host we are operating with. Populated right before calling the task

Type:nornir.core.inventory.Host
nornir

Populated right before calling the task

Type:nornir.core.Nornir
severity_level

Severity level associated to the task

Type:logging.LEVEL
copy() → nornir.core.task.Task
is_dry_run(override: Optional[bool] = None) → bool

Returns whether current task is a dry_run or not.

run(task: Callable[..., Any], **kwargs) → nornir.core.task.MultiResult

This is a utility method to 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.

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 the task
  • nornir (nornir.core.Nornir) – Populated right before calling the task
Returns:

Results of the task and its subtasks

Return type:

host (nornir.core.task.MultiResult)