tasks

nornir_utils.plugins.tasks.data.echo_data(task: Task, **kwargs: Any) Result

Dummy task that echoes the data passed to it. Useful in grouped_tasks to debug data passed to tasks.

Parameters:

**kwargs – Any <key,value> pair you want

Returns:

  • result (dict): **kwargs passed to the task

Return type:

Result object with the following attributes set

nornir_utils.plugins.tasks.data.load_json(task: Task, file: str) Result

Loads a json file.

Parameters:

file – path to the file containing the json file to load

Examples

Simple example with ordered_dict:

> nr.run(task=load_json,
         file="mydata.json")

file: path to the file containing the json file to load

Returns:

  • result (dict): dictionary with the contents of the file

Return type:

Result object with the following attributes set

nornir_utils.plugins.tasks.data.load_yaml(task: Task, file: str) Result

Loads a yaml file.

Parameters:

file – path to the file containing the yaml file to load

Examples

Simple example with ordered_dict:

> nr.run(task=load_yaml,
         file="mydata.yaml")
Returns:

  • result (dict): dictionary with the contents of the file

Return type:

Result object with the following attributes set

nornir_utils.plugins.tasks.files.write_file(task: Task, filename: str, content: str, append: bool = False, dry_run: Optional[bool] = None) Result

Write contents to a file (locally)

Parameters:
  • dry_run – Whether to apply changes or not

  • filename – file you want to write into

  • content – content you want to write

  • append – whether you want to replace the contents or append to it

Returns:

  • changed (bool):

  • diff (str): unified diff

Return type:

Result object with the following attributes set

nornir_utils.plugins.tasks.networking.tcp_ping(task: Task, ports: List[int], timeout: int = 2, host: Optional[str] = None) Result

Tests connection to a tcp port and tries to establish a three way handshake. To be used for network discovery or testing.

Parameters:
  • ports (list of int) – tcp ports to ping

  • timeout (int, optional) – defaults to 2

  • host (string, optional) – defaults to hostname

Returns:

  • result (dict): Contains port numbers as keys with True/False as values

Return type:

Result object with the following attributes set