netmiko_send_commands

This task plugin uses nornir-netmiko netmiko_send_command task to send multiple commands to devices.

Dependencies:

netmiko_send_commands sample usage

Code to invoke netmiko_send_commands task:

from nornir_salt.plugins.tasks import netmiko_send_commands

output = nr.run(
    task=netmiko_send_commands,
    commands=["show run", "show clock"]
)

netmiko_send_commands returns

Returns Nornir results object with individual tasks names set equal to commands sent to device.

netmiko_send_commands reference

nornir_salt.plugins.tasks.netmiko_send_commands.netmiko_send_commands(task: nornir.core.task.Task, commands: list = None, interval: float = 0.01, use_ps: bool = False, split_lines: bool = True, new_line_char: str = '_br_', repeat: int = 1, stop_pattern: str = None, repeat_interval: int = 1, return_last: int = None, **kwargs)

Nornir Task function to send show commands to devices using nornir_netmiko.tasks.netmiko_send_command plugin

Per-host commands can be provided using host’s object data attribute with __task__ key with value set to dictionary with commands key containing a list of or a multiline string of commands to send to device, e.g.:

print(host.data["__task__"]["commands"])

["ping 1.1.1.1 source 1.1.1.2", "show clock"]

Alternatively, __task__ can contain filename key with commands string to send to device.

Parameters
  • kwargs – (dict) any additional arguments to pass to netmiko_send_command nornir-netmiko task

  • commands – (list or str) list or multiline string of commands to send to device

  • interval – (int) interval between sending commands

  • use_ps – (bool) set to True to switch to experimental send_command_ps method

  • split_lines – (bool) if True split multiline string to commands, send multiline string to device as is otherwise

  • new_line_char – (str) characters to replace in commands with new line \n before sending command to device, default is _br_, useful to simulate enter key

  • repeat – (int) - number of times to repeat the commands

  • stop_pattern – (str) - stop commands repeat if at least one of commands output matches provided glob pattern

  • repeat_interval – (int) time in seconds to wait between repeating all commands

  • return_last – (int) if repeat greater then 1, returns requested last number of commands outputs

Return result

Nornir result object with task results named after commands