netmiko_send_config

This task plugin relies on Netmiko conection send_config_set method to send configuration commands to devices over SSH or Telnet.

This task plugin applies device configuration following this sequence:

  • Retrieve and use, if any, per-host configuration rendered by SaltStack from host’s inventory data task.host.data["__task__"]["commands"] or task.host.data["__task__"]["filename"] locations, use configuration provided by config argument otherwise

  • If configuration is a multi-line string, split it to a list of commands

  • Check if device in enable mode, if not enter device enabled mode if device supports it

  • Push configuration commands to device using send_config_set Netmiko connection’s method, if batch argument given, pushes commands in batches

  • If commit argument provided, perform configuration commit if device supports it

  • If commit_final_delay argument provided, wait for a given timer and perform final commit

  • Exit device configuration mode and return configuration results

Dependencies:

netmiko_send_config sample usage

Code to invoke netmiko_send_config task:

from nornir_salt.plugins.tasks import netmiko_send_config

output = nr.run(
    task=netmiko_send_config,
    commands=["interface loopback 0", "description 'configured by script'"]
)

netmiko_send_config returns

Returns Nornir results object with task name set to netmiko_send_config and results containing commands execution CLI output.

netmiko_send_config reference

nornir_salt.plugins.tasks.netmiko_send_config.netmiko_send_config(task: nornir.core.task.Task, config=None, commit=True, commit_final_delay=0, batch=0, enable=True, **kwargs)

Salt-nornir Task function to send configuration to devices using nornir_netmiko.tasks.netmiko_send_config plugin.

Parameters
  • kwargs – (dict) any additional arguments to use with nornir_netmiko.tasks.netmiko_send_config task plugin

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

  • commit – (bool or dict) by default commit is True, as a result host connection commit method will be called. If commit argument is a dictionary, it will be supplied to connection’s commit method call as **commit.

  • commit_final_delay – (int) time to wait before doing final commit, can be used in conjunction with commit confirm feature if device supports it.

  • batch – (int) commands count to send in batches, sends all at once by default

  • enable – (bool) if True (default), attempts to enter enable-mode

Return result

Nornir result object with task execution results

Default parameters supplied to netmiko_send_config function call:

cmd_verify: False
exit_config_mode: False if batch provided or commit is True else unmodified

Batch mode controlled by batch parameter, by default all configuration commands send at once, but that approach might lead to Netmiko timeout errors if device takes too long to respond, sending commands in batches helps to overcome that problem.