salt.modules.netmiko_mod
Netmiko Execution Module
New in version 2019.2.0.
Execution module to interface the connection with a remote network device. It is flexible enough to execute the commands both when running under a Netmiko Proxy Minion, as well as running under a Regular Minion by specifying the connection arguments, i.e., device_type
, ip
, username
, password
etc.
- codeauthor
-
Mircea Ulinic <ping@mirceaulinic.net> & Kirk Byers <ktbyers@twb-tech.com>
- maturity
-
new
- depends
-
netmiko
- platform
-
unix
Dependencies
The netmiko
proxy modules requires Netmiko to be installed: pip install netmiko
.
Usage
This module can equally be used via the netmiko
Proxy module (check documentation), or directly from an arbitrary (Proxy) Minion that is running on a server (computer) having access to the network device, and has the netmiko
library installed.
When running outside of the netmiko Proxy
(i.e., from another Proxy Minion type, or regular Minion), the netmiko connection arguments can be either specified from the CLI when executing the command, or in a configuration block under the netmiko
key in the configuration opts (i.e., (Proxy) Minion configuration file), or Pillar. The module supports these simultaneously. These fields are the exact same supported by the netmiko
Proxy Module:
-
device_type
- Class selection based on device type. Supported options:a10
: A10 Networksaccedian
: Accedian Networksalcatel_aos
: Alcatel AOSalcatel_sros
: Alcatel SROSapresia_aeos
: Apresia AEOSarista_eos
: Arista EOSaruba_os
: Arubaavaya_ers
: Avaya ERSavaya_vsp
: Avaya VSPbrocade_fastiron
: Brocade Fastironbrocade_netiron
: Brocade Netironbrocade_nos
: Brocade NOSbrocade_vdx
: Brocade NOSbrocade_vyos
: VyOScheckpoint_gaia
: Check Point GAiAcalix_b6
: Calix B6ciena_saos
: Ciena SAOScisco_asa
: Cisco SAcisco_ios
: Cisco IOScisco_nxos
: Cisco NX-oScisco_s300
: Cisco S300cisco_tp
: Cisco TpTcCecisco_wlc
: Cisco WLCcisco_xe
: Cisco IOScisco_xr
: Cisco XRcoriant
: Coriantdell_force10
: Dell Force10dell_os10
: Dell OS10dell_powerconnect
: Dell PowerConnecteltex
: Eltexenterasys
: Enterasysextreme
: Extremeextreme_wing
: Extreme Wingf5_ltm
: F5 LTMfortinet
: Fortinetgeneric_termserver
: TerminalServerhp_comware
: HP Comwarehp_procurve
: HP Procurvehuawei
: Huaweihuawei_vrpv8
: Huawei VRPV8juniper
: Juniper Junosjuniper_junos
: Juniper Junoslinux
: Linuxmellanox
: Mellanoxmrv_optiswitch
: MrvOptiswitchnetapp_cdot
: NetAppcDotnetscaler
: Netscalerovs_linux
: OvsLinuxpaloalto_panos
: PaloAlto Panospluribus
: Pluribusquanta_mesh
: Quanta Meshruckus_fastiron
: Ruckus Fastironubiquiti_edge
: Ubiquiti Edgeubiquiti_edgeswitch
: Ubiquiti Edgevyatta_vyos
: VyOSvyos
: VyOSbrocade_fastiron_telnet
: Brocade Fastiron over Telnetbrocade_netiron_telnet
: Brocade Netiron over Telnetcisco_ios_telnet
: Cisco IOS over Telnetapresia_aeos_telnet
: Apresia AEOS over Telnetarista_eos_telnet
: Arista EOS over Telnethp_procurve_telnet
: HP Procurve over Telnethp_comware_telnet
: HP Comware over Telnetjuniper_junos_telnet
: Juniper Junos over Telnetcalix_b6_telnet
: Calix B6 over Telnetdell_powerconnect_telnet
: Dell PowerConnect over Telnetgeneric_termserver_telnet
: TerminalServer over Telnetextreme_telnet
: Extreme Networks over Telnetruckus_fastiron_telnet
: Ruckus Fastiron over Telnetcisco_ios_serial
: Cisco IOS over serial port
ip
- IP address of target device (not required ifhost
is provided)host
- Hostname of target device (not required ifip
is provided)username
- Username to authenticate against target device, if requiredpassword
- Password to authenticate against target device, if requiredsecret
- The enable password if target device requires oneport
- The destination port used to connect to the target deviceglobal_delay_factor
- Multiplication factor affecting Netmiko delays (default:1
)use_keys
- Connect to target device using SSH keys (default:False
)key_file
- Filename path of the SSH key file to useallow_agent
- Enable use of SSH key-agentssh_strict
- Automatically reject unknown SSH host keys (default:False
, which means unknown SSH host keys will be accepted)system_host_keys
- Load host keys from the user's "known_hosts" file (default:False
)alt_host_keys
- IfTrue
, host keys will be loaded from the file specified inalt_key_file
(default:False
)alt_key_file
- SSH host key file to use (ifalt_host_keys=True
)ssh_config_file
- File name of OpenSSH configuration filetimeout
- Connection timeout, in seconds (default:90
)session_timeout
- Set a timeout for parallel requests, in seconds (default:60
)keepalive
- Send SSH keepalive packets at a specific interval, in seconds. Currently defaults to0
, for backwards compatibility (it will not attempt to keep the connection alive using the KEEPALIVE packets).default_enter
- Character(s) to send to correspond to enter key (default:\n
)response_return
- Character(s) to use in normalized return data to represent enter key (default:\n
)
Example (when not running in a netmiko
Proxy Minion):
netmiko: username: test password: test
In case the username
and password
are the same on any device you are targeting, the block above (besides other parameters specific to your environment you might need) should suffice to be able to execute commands from outside a netmiko
Proxy, e.g.:
salt '*' netmiko.send_command 'show version' host=router1.example.com device_type=juniper salt '*' netmiko.send_config https://bit.ly/2sgljCB host=sw2.example.com device_type=cisco_ios
Note
Remember that the above applies only when not running in a netmiko
Proxy Minion. If you want to use the <salt.proxy.netmiko_px>
, please follow the documentation notes for a proper setup.
-
Invoke an arbitrary Netmiko method.
- method
-
The name of the Netmiko method to invoke.
- args
-
A list of arguments to send to the method invoked.
- kwargs
-
Key-value dictionary to send to the method invoked.
salt.modules.netmiko_mod.call(method, *args, **kwargs)
-
Commit the configuration changes.
Warning
This function is supported only on the platforms that support the
commit
operation.CLI Example:
salt '*' netmiko.commit
salt.modules.netmiko_mod.commit(**kwargs)
-
Enter into config mode.
- config_command
-
Configuration command to send to the device.
- pattern
-
Pattern to terminate reading of channel.
CLI Example:
salt '*' netmiko.enter_config_mode salt '*' netmiko.enter_config_mode device_type='juniper_junos' ip='192.168.0.1' username='example'
salt.modules.netmiko_mod.enter_config_mode(**kwargs)
-
Exit from configuration mode.
- exit_config
-
Command to exit configuration mode.
- pattern
-
Pattern to terminate reading of channel.
CLI Example:
salt '*' netmiko.exit_config_mode salt '*' netmiko.exit_config_mode device_type='juniper' ip='192.168.0.1' username='example'
salt.modules.netmiko_mod.exit_config_mode(**kwargs)
-
Return the Netmiko connection object.
Warning
This function returns an unserializable object, hence it is not meant to be used on the CLI. This should mainly be used when invoked from other modules for the low level connection with the network device.
- kwargs
-
Key-value dictionary with the authentication details.
USAGE Example:
conn = __salt__['netmiko.get_connection'](host='router1.example.com', username='example', password='example') show_if = conn.send_command('show interfaces') conn.disconnect()
salt.modules.netmiko_mod.get_connection(**kwargs)
-
Invoke multiple Netmiko methods at once, and return their output, as list.
- methods
-
A list of dictionaries with the following keys:
name
: the name of the Netmiko method to be executed.args
: list of arguments to be sent to the Netmiko method.kwargs
: dictionary of arguments to be sent to the Netmiko method.
- kwargs
-
Key-value dictionary with the connection details (when not running under a Proxy Minion).
salt.modules.netmiko_mod.multi_call(*methods, **kwargs)
-
Execute command_string on the SSH channel using a pattern-based mechanism. Generally used for show commands. By default this method will keep waiting to receive data until the network device prompt is detected. The current network device prompt will be determined automatically.
- command_string
-
The command to be executed on the remote device.
- expect_string
-
Regular expression pattern to use for determining end of output. If left blank will default to being based on router prompt.
- delay_factor:
1
-
Multiplying factor used to adjust delays (default:
1
). - max_loops:
500
-
Controls wait time in conjunction with delay_factor. Will default to be based upon self.timeout.
- auto_find_prompt:
True
-
Whether it should try to auto-detect the prompt (default:
True
). - strip_prompt:
True
-
Remove the trailing router prompt from the output (default:
True
). - strip_command:
True
-
Remove the echo of the command from the output (default:
True
). - normalize:
True
-
Ensure the proper enter is sent at end of command (default:
True
). - use_textfsm:
False
-
Process command output through TextFSM template (default:
False
).
CLI Example:
salt '*' netmiko.send_command 'show version' salt '*' netmiko.send_command 'show_version' host='router1.example.com' username='example' device_type='cisco_ios'
salt.modules.netmiko_mod.send_command(command_string, **kwargs)
-
Execute command_string on the SSH channel using a delay-based mechanism. Generally used for show commands.
- command_string
-
The command to be executed on the remote device.
- delay_factor:
1
-
Multiplying factor used to adjust delays (default:
1
). - max_loops:
500
-
Controls wait time in conjunction with delay_factor. Will default to be based upon self.timeout.
- strip_prompt:
True
-
Remove the trailing router prompt from the output (default:
True
). - strip_command:
True
-
Remove the echo of the command from the output (default:
True
). - normalize:
True
-
Ensure the proper enter is sent at end of command (default:
True
). - use_textfsm:
False
-
Process command output through TextFSM template (default:
False
).
CLI Example:
salt '*' netmiko.send_command_timing 'show version' salt '*' netmiko.send_command_timing 'show version' host='router1.example.com' username='example' device_type='arista_eos'
salt.modules.netmiko_mod.send_command_timing(command_string, **kwargs)
-
Send configuration commands down the SSH channel. Return the configuration lines sent to the device.
The function is flexible to send the configuration from a local or remote file, or simply the commands as list.
- config_file
-
The source file with the configuration commands to be sent to the device.
The file can also be a template that can be rendered using the template engine of choice.
This can be specified using the absolute path to the file, or using one of the following URL schemes:
salt://
, to fetch the file from the Salt fileserver.http://
orhttps://
ftp://
s3://
swift://
- config_commands
-
Multiple configuration commands to be sent to the device.
Note
This argument is ignored when
config_file
is specified. - template_engine:
jinja
-
The template engine to use when rendering the source file. Default:
jinja
. To simply fetch the file without attempting to render, set this argument toNone
. - commit:
False
-
Commit the configuration changes before exiting the config mode. This option is by default disabled, as many platforms don't have this capability natively.
- context
-
Variables to add to the template context.
- defaults
-
Default values of the context_dict.
- exit_config_mode:
True
-
Determines whether or not to exit config mode after complete.
- delay_factor:
1
-
Factor to adjust delays.
- max_loops:
150
-
Controls wait time in conjunction with delay_factor (default:
150
). - strip_prompt:
False
-
Determines whether or not to strip the prompt (default:
False
). - strip_command:
False
-
Determines whether or not to strip the command (default:
False
). - config_mode_command
-
The command to enter into config mode.
CLI Example:
salt '*' netmiko.send_config config_commands="['interface GigabitEthernet3', 'no ip address']" salt '*' netmiko.send_config config_commands="['snmp-server location {{ grains.location }}']" salt '*' netmiko.send_config config_file=salt://config.txt salt '*' netmiko.send_config config_file=https://bit.ly/2sgljCB device_type='cisco_ios' ip='1.2.3.4' username='example'
salt.modules.netmiko_mod.send_config(config_file=None, config_commands=None, template_engine='jinja', commit=False, context=None, defaults=None, saltenv='base', **kwargs)
© 2021 SaltStack.
Licensed under the Apache License, Version 2.0.
https://docs.saltproject.io/en/latest/ref/modules/all/salt.modules.netmiko_mod.html