Salt is very well structured. A very important functionality is represented by the execution modules. They are the main entry point into the Salt world. The execution modules are Python modules, and are very easy to read (and eventually write) by anyone with basic Python programming knowledge. Everything is linear, which makes them flexible and easy to understand; in general, they consist only of simple functions.
For complete list of modules – refer to Salt Module Index. It’s respective python repository can be found at Github.
Refer to below image for “salt” cli syntax.

In this post, we will look at the most frequently used module
Grains Module
Function: “items”
Purpose: To collect all grains from the managed system.
root@mrcissp-master-1:/# salt '*' grains.items Router1: ---------- cpuarch: x86_64 dns: ---------- domain: ip4_nameservers: - 8.8.8.8 ip6_nameservers: nameservers: - 8.8.8.8 options: search: sortlist: fqdns: gpus: host: 192.168.200.1 hostname: R1 hwaddr_interfaces: ---------- eth0: d2:32:87:c9:f2:8f id: Router1 interfaces: - GigabitEthernet0/0 - GigabitEthernet0/1 - GigabitEthernet0/2 - GigabitEthernet0/3 - Loopback0 kernel: proxy kernelrelease: proxy kernelversion: proxy locale_info: ---------- machine_id: 578962dbb63ae45b159330245dd26e77 master: 192.168.100.2 mem_total: 0 model: IOSv nodename: mrcissp-minion-1 num_gpus: 0 optional_args: ---------- config_lock: False keepalive: 5 os: ios os_family: proxy osarch: x86_64 osfinger: proxy-proxy osfullname: proxy osrelease: proxy osrelease_info: - proxy path: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin ps: ps -efHww pythonexecutable: /usr/bin/python pythonpath: - /usr/local/bin - /usr/lib/python2.7 - /usr/lib/python2.7/plat-x86_64-linux-gnu - /usr/lib/python2.7/lib-tk - /usr/lib/python2.7/lib-old - /usr/lib/python2.7/lib-dynload - /usr/local/lib/python2.7/dist-packages - /usr/lib/python2.7/dist-packages pythonversion: - 2 - 7 - 15 - final - 0 saltpath: /usr/local/lib/python2.7/dist-packages/salt saltversion: 2019.2.2 saltversioninfo: - 2019 - 2 - 2 - 0 serial: 97277GPG1FLKXDX5WL1G0 shell: /bin/sh uptime: 240 username: mrcissp vendor: Cisco version: IOSv Software (VIOS-ADVENTERPRISEK9-M), Version 15.6(2)T, RELEASE SOFTWARE (fc2) virtual: VMware zmqversion: 4.3.2 wlc1: ---------- cpuarch: x86_64 dns: ---------- domain: ip4_nameservers: - 8.8.8.8 ip6_nameservers: nameservers: - 8.8.8.8 options: search: sortlist: fqdns: gpus: hwaddr_interfaces: ---------- eth0: d2:32:87:c9:f2:8f id: wlc1 kernel: proxy kernelrelease: proxy kernelversion: proxy locale_info: ---------- machine_id: 578962dbb63ae45b159330245dd26e77 master: 192.168.100.2 mem_total: 0 nodename: mrcissp-minion-1 num_gpus: 0 os: proxy os_family: proxy osarch: x86_64 osfinger: proxy-proxy osfullname: proxy osrelease: proxy osrelease_info: - proxy path: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin ps: ps -efHww pythonexecutable: /usr/bin/python pythonpath: - /usr/local/bin - /usr/lib/python2.7 - /usr/lib/python2.7/plat-x86_64-linux-gnu - /usr/lib/python2.7/lib-tk - /usr/lib/python2.7/lib-old - /usr/lib/python2.7/lib-dynload - /usr/local/lib/python2.7/dist-packages - /usr/lib/python2.7/dist-packages pythonversion: - 2 - 7 - 15 - final - 0 saltpath: /usr/local/lib/python2.7/dist-packages/salt saltversion: 2019.2.2 saltversioninfo: - 2019 - 2 - 2 - 0 shell: /bin/sh virtual: VMware zmqversion: 4.3.2 mrcissp-minion-1: ---------- SSDs: biosreleasedate: 07/29/2019 biosversion: 6.00 cpu_flags: - fpu - vme - de - pse - tsc - msr - pae - mce - cx8 - apic - sep - mtrr - pge - mca - cmov - pat - pse36 - clflush - mmx - fxsr - sse - sse2 - ss - ht - syscall - nx - pdpe1gb - rdtscp - lm - constant_tsc - arch_perfmon - nopl - xtopology - tsc_reliable - nonstop_tsc - cpuid - pni - pclmulqdq - vmx - ssse3 - fma - cx16 - pcid - sse4_1 - sse4_2 - x2apic - movbe - popcnt - aes - xsave - avx - f16c - rdrand - hypervisor - lahf_lm - 3dnowprefetch - cpuid_fault - pti - ssbd - ibrs - ibpb - stibp - tpr_shadow - vnmi - ept - vpid - fsgsbase - smep - arat - flush_l1d - arch_capabilities cpu_model: Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz cpuarch: x86_64 disks: - loop1 - sdb - loop6 - loop4 - sr0 - loop2 - loop0 - loop7 - sda - loop5 - loop3 dns: ---------- domain: ip4_nameservers: - 8.8.8.8 ip6_nameservers: nameservers: - 8.8.8.8 options: search: sortlist: domain: fqdn: mrcissp-minion-1 fqdn_ip4: - 127.0.1.1 fqdn_ip6: fqdns: gid: 0 gpus: groupname: root host: mrcissp-minion-1 hwaddr_interfaces: ---------- eth0: d2:32:87:c9:f2:8f id: mrcissp-minion-1 init: unknown ip4_interfaces: ---------- eth0: - 192.168.100.3 lo: - 127.0.0.1 ip6_interfaces: ---------- eth0: - fe80::d032:87ff:fec9:f28f lo: - ::1 ip_interfaces: ---------- eth0: - 192.168.100.3 - fe80::d032:87ff:fec9:f28f lo: - 127.0.0.1 - ::1 ipv4: - 127.0.0.1 - 192.168.100.3 ipv6: - ::1 - fe80::d032:87ff:fec9:f28f kernel: Linux kernelrelease: 4.15.0-55-generic kernelversion: #60-Ubuntu SMP Tue Jul 2 18:22:20 UTC 2019 locale_info: ---------- defaultencoding: None defaultlanguage: None detectedencoding: ANSI_X3.4-1968 timezone: unknown localhost: mrcissp-minion-1 lsb_distrib_codename: bionic lsb_distrib_description: Ubuntu 18.04.3 LTS lsb_distrib_id: Ubuntu lsb_distrib_release: 18.04 machine_id: 578962dbb63ae45b159330245dd26e77 manufacturer: VMware, Inc. master: 192.168.100.2 mdadm: mem_total: 3944 nodename: mrcissp-minion-1 num_cpus: 4 num_gpus: 0 os: Ubuntu os_family: Debian osarch: amd64 oscodename: bionic osfinger: Ubuntu-18.04 osfullname: Ubuntu osmajorrelease: 18 osrelease: 18.04 osrelease_info: - 18 - 4 path: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin pid: 4560 productname: VMware Virtual Platform ps: ps -efHww pythonexecutable: /usr/bin/python pythonpath: - /usr/local/bin - /usr/lib/python2.7 - /usr/lib/python2.7/plat-x86_64-linux-gnu - /usr/lib/python2.7/lib-tk - /usr/lib/python2.7/lib-old - /usr/lib/python2.7/lib-dynload - /usr/local/lib/python2.7/dist-packages - /usr/lib/python2.7/dist-packages pythonversion: - 2 - 7 - 15 - final - 0 saltpath: /usr/local/lib/python2.7/dist-packages/salt saltversion: 2019.2.2 saltversioninfo: - 2019 - 2 - 2 - 0 serialnumber: VMware-56 4d e4 6c d3 e5 53 d5-0c 20 c1 55 a4 0e b9 4e server_id: 822305722 shell: /bin/sh swap_total: 924 systemd: ---------- features: +PAM +AUDIT +SELINUX +IMA +APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD -IDN2 +IDN -PCRE2 default-hierarchy=hybrid version: 237 uid: 0 username: root uuid: 564de46c-d3e5-53d5-0c20-c155a40eb94e virtual: VMware virtual_subtype: Docker zfs_feature_flags: False zfs_support: False zmqversion: 4.3.2
Note: When devices is managed by NAPALM i.e. in this case “Router1” – additional grains are collected. Details of these grains can found at Saltstack documentation.
We can also observe that not many grains are found on WLC i.e. “wlc1”. Because of following reasons
- It is managed by “netmiko”
- By default – there is not any existing module for grains collected by “netmiko”
Function: “get”
Purpose: To get the value of a given grain.
Argument: requested grain
root@mrcissp-master-1:/# salt '*' grains.get os wlc1: proxy Router1: ios mrcissp-minion-1: Ubuntu root@mrcissp-master-1:/# salt '*' grains.get master wlc1: 192.168.100.2 Router1: 192.168.100.2 mrcissp-minion-1: 192.168.100.2 root@mrcissp-master-1:/# salt '*' grains.get host Router1: 192.168.200.1 wlc1: mrcissp-minion-1: mrcissp-minion-1 root@mrcissp-master-1:/#
Pillar Module
Function: “items”
Purpose: To collect all pillar found at a Minion.
root@mrcissp-master-1:/# salt '*' pillar.items Router1: ---------- proxy: ---------- driver: ios host: 192.168.200.1 passwd: Nvidia@123 proxytype: napalm username: mrcissp wlc1: ---------- proxy: ---------- device_type: cisco_wlc ip: 192.168.241.2 password: Nvidia@123 proxytype: netmiko username: mrcissp mrcissp-minion-1: ----------
Function: “get”
Purpose: to get a value of given pillar.
root@mrcissp-master-1:/# salt '*' pillar.get proxy wlc1: ---------- device_type: cisco_wlc ip: 192.168.241.2 password: Nvidia@123 proxytype: netmiko username: mrcissp Router1: ---------- driver: ios host: 192.168.200.1 passwd: Nvidia@123 proxytype: napalm username: mrcissp mrcissp-minion-1:
Test Module
Function: “ping”
Purpose: Verify connectivity from Master to Minion and to check if Minion is configured properly.
root@mrcissp-master-1:/# salt '*' test.ping wlc1: True Router1: True mrcissp-minion-1: True root@mrcissp-master-1:/#
Netmiko Module
Function: “send_command”
Purpose: 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.
root@mrcissp-master-1:/# salt wlc1 netmiko.send_command 'show sysinfo' wlc1: Manufacturer's Name.............................. Cisco Systems Inc. Product Name..................................... Cisco Controller Product Version.................................. 8.9.111.0 RTOS Version..................................... 8.9.111.0 Bootloader Version............................... 8.5.1.85 Emergency Image Version.......................... 8.9.111.0 OUI File Last Update Time........................ Tue Feb 06 10:44:07 UTC 2018 r,aes192-ctr,aes256-ctr,aes128-cbc,aes192-cbc,aes256-cbc,blowfish-cbc,3des-cbc Build Type....................................... DATA + WPS System Name...................................... Cisco-0c0c.9da2.b501 System Location.................................. System Contact................................... System ObjectID.................................. 1.3.6.1.4.1.9.1.1631 IP Address....................................... 192.168.241.2 IPv6 Address..................................... :: System Up Time................................... 0 days 0 hrs 34 mins 4 secs System Timezone Location......................... System Stats Realtime Interval................... 5 System Stats Normal Interval..................... 180 Configured Country............................... US - United States State of 802.11b Network......................... Enabled State of 802.11a Network......................... Enabled Number of WLANs.................................. 1 Number of Active Clients......................... 0 OUI Classification Failure Count................. 0 Memory Current Usage............................. 52 Memory Average Usage............................. 52 CPU Current Usage................................ 0 CPU Average Usage................................ 0 Flash Type....................................... Compact Flash Card Flash Size....................................... 1073741824 Burned-in MAC Address............................ 0C:0C:9D:A2:B5:01 Maximum number of APs supported.................. 200 System Nas-Id.................................... WLC MIC Certificate Types........................ SHA1 Licensing Type................................... RTU vWLC config...................................... Small
Net Module (aka napalm_network)
Virtual name of “napalm_network” module
Function: “connected”
Purpose: Verify connectivity from Master to Network devices managed by “napalm” proxy.
root@mrcissp-master-1:/# salt Router1 net.connected Router1: ---------- out: True root@mrcissp-master-1:/#
Function: “arp”
Purpose: to get arp entries on all interfaces.
root@mrcissp-master-1:/# salt Router1 net.arp Router1: ---------- comment: out: |_ ---------- age: 0.0 interface: GigabitEthernet0/0 ip: 192.168.100.1 mac: 0C:0C:9D:A4:BF:00 |_ ---------- age: 0.0 interface: GigabitEthernet0/0 ip: 192.168.100.2 mac: 56:EC:C7:5B:E8:9C |_ ---------- age: 65.0 interface: GigabitEthernet0/0 ip: 192.168.100.3 mac: D2:32:87:C9:F2:8F |_ ---------- age: 1.0 interface: GigabitEthernet0/1 ip: 192.168.108.2 mac: 00:50:56:E5:45:56 |_ ---------- age: 0.0 interface: GigabitEthernet0/1 ip: 192.168.108.131 mac: 0C:0C:9D:A4:BF:01 |_ ---------- age: 53.0 interface: GigabitEthernet0/1 ip: 192.168.108.254 mac: 00:50:56:ED:B5:FA |_ ---------- age: 0.0 interface: GigabitEthernet0/2 ip: 192.168.240.1 mac: 0C:0C:9D:A4:BF:02 |_ ---------- age: 68.0 interface: GigabitEthernet0/2 ip: 192.168.240.2 mac: 0C:0C:9D:77:06:00 result: True
Napalm Module (aka napalm_mod)
Virtual name of “napalm_mod” module
Function: “call”
Purpose: To execute remote commands on the devices.
root@mrcissp-master-1:/# salt Router1 napalm.call 'cli' ['show version','show ip int br'] Router1: ---------- comment: out: ---------- show ip int br: Interface IP-Address OK? Method Status Protocol GigabitEthernet0/0 192.168.100.1 YES NVRAM up up GigabitEthernet0/1 192.168.108.131 YES DHCP up up GigabitEthernet0/2 192.168.240.1 YES NVRAM up up GigabitEthernet0/3 unassigned YES NVRAM administratively down down Loopback0 192.168.200.1 YES NVRAM up up show version: Cisco IOS Software, IOSv Software (VIOS-ADVENTERPRISEK9-M), Version 15.6(2)T, RELEASE SOFTWARE (fc2) Technical Support: http://www.cisco.com/techsupport Copyright (c) 1986-2016 by Cisco Systems, Inc. Compiled Tue 22-Mar-16 16:19 by prod_rel_team ROM: Bootstrap program is IOSv R1 uptime is 1 hour, 10 minutes System returned to ROM by reload System restarted at 18:45:09 UTC Sun Nov 24 2019 System image file is "flash0:/vios-adventerprisek9-m" Last reload reason: Unknown reason This product contains cryptographic features and is subject to United States and local country laws governing import, export, transfer and use. Delivery of Cisco cryptographic products does not imply third-party authority to import, export, distribute or use encryption. Importers, exporters, distributors and users are responsible for compliance with U.S. and local country laws. By using this product you agree to comply with applicable laws and regulations. If you are unable to comply with U.S. and local laws, return this product immediately. A summary of U.S. laws governing Cisco cryptographic products may be found at: http://www.cisco.com/wwl/export/crypto/tool/stqrg.html If you require further assistance please contact us by sending email to export@cisco.com. Cisco IOSv (revision 1.0) with with 460017K/62464K bytes of memory. Processor board ID 97277GPG1FLKXDX5WL1G0 4 Gigabit Ethernet interfaces DRAM configuration is 72 bits wide with parity disabled. 256K bytes of non-volatile configuration memory. 2097152K bytes of ATA System CompactFlash 0 (Read/Write) 0K bytes of ATA CompactFlash 1 (Read/Write) 1024K bytes of ATA CompactFlash 2 (Read/Write) 0K bytes of ATA CompactFlash 3 (Read/Write) Configuration register is 0x0 result: True root@mrcissp-master-1:/#
Sys Module
Function: “ list_modules ”
Purpose: To get list of loaded modules with their virtual names.
root@mrcissp-master-1:/# salt '*' sys.list_modules Router1: - aliases - alternatives - ansible - archive - artifactory - beacons - bgp - bigip - buildout - chassis - chronos - ciscoconfparse - cisconso - cloud - cmd - composer - config - consul - container_resource - cp - cpan - cryptdev - data - ddns - defaults - devmap - disk - django - dnsmasq - dnsutil - drbd - environ - esxcluster - esxdatacenter - esxi - esxvm - etcd - ethtool - event - extfs - file - gem - genesis - git - glassfish - gnome - google_chat - grafana4 - grains - hashutil - highstate_doc - hipchat - hosts - http - hue - incron - ini - inspector - introspect - iosconfig - jboss7 - jboss7_cli - k8s - key - keyboard - locale - locate - log - logrotate - mandrill - marathon - match - mattermost - mine - minion - modjk - mount - msteams - nagios_rpc - namecheap_domains - namecheap_domains_dns - namecheap_domains_ns - namecheap_ssl - namecheap_users - napalm - napalm_bgp - napalm_formula - napalm_net - napalm_ntp - napalm_route - napalm_snmp - napalm_users - net - netaddress - netmiko - network - nexus - nova - ntp - nxos - nxos_api - openscap - openstack_config - opsgenie - out - pagerduty - pagerduty_util - pam - parallels - peeringdb - pillar - pip - pkg_resource - probes - publish - pushover - pyeapi - pyenv - random - random_org - rbenv - rest_sample_utils - ret - route - rvm - s3 - s6 - salt_proxy - saltcheck - saltutil - schedule - scp - scsi - sdb - seed - serverdensity_device - slack - slsutil - smbios - smtp - snmp - solrcloud - sqlite3 - ssh - state - status - statuspage - supervisord - sys - sysfs - syslog_ng - system - telegram - telemetry - temp - test - textfsm - timezone - uptime - users - vault - vcenter - virtualenv - vsphere - zabbix - zenoss wlc1: - aliases - alternatives - ansible - archive - artifactory - beacons - bigip - buildout - chassis - chronos - ciscoconfparse - cisconso - cloud - cmd - composer - config - consul - container_resource - cp - cpan - cryptdev - data - ddns - defaults - devmap - disk - django - dnsmasq - dnsutil - drbd - environ - esxcluster - esxdatacenter - esxi - esxvm - etcd - ethtool - event - extfs - file - gem - genesis - git - glassfish - gnome - google_chat - grafana4 - grains - hashutil - highstate_doc - hipchat - hosts - http - hue - incron - ini - inspector - introspect - iosconfig - jboss7 - jboss7_cli - k8s - key - keyboard - locale - locate - log - logrotate - mandrill - marathon - match - mattermost - mine - minion - modjk - mount - msteams - nagios_rpc - namecheap_domains - namecheap_domains_dns - namecheap_domains_ns - namecheap_ssl - namecheap_users - netaddress - netmiko - network - nexus - nova - nxos - nxos_api - openscap - openstack_config - opsgenie - out - pagerduty - pagerduty_util - pam - parallels - peeringdb - pillar - pip - pkg_resource - publish - pushover - pyeapi - pyenv - random - random_org - rbenv - rest_sample_utils - ret - rvm - s3 - s6 - salt_proxy - saltcheck - saltutil - schedule - scp - scsi - sdb - seed - serverdensity_device - slack - slsutil - smbios - smtp - solrcloud - sqlite3 - ssh - state - status - statuspage - supervisord - sys - sysfs - syslog_ng - system - telegram - telemetry - temp - test - textfsm - timezone - uptime - vault - vcenter - virtualenv - vsphere - zabbix - zenoss mrcissp-minion-1: - aliases - alternatives - ansible - archive - artifactory - beacons - bigip - btrfs - buildout - ciscoconfparse - cloud - cmd - composer - config - consul - container_resource - cp - cpan - cryptdev - data - ddns - debconf - defaults - devmap - disk - django - dnsmasq - dnsutil - drbd - environ - etcd - ethtool - event - extfs - file - gem - genesis - git - glassfish - gnome - google_chat - grafana4 - grains - group - hashutil - highstate_doc - hipchat - hosts - http - incron - ini - inspector - introspect - iosconfig - ip - jboss7 - jboss7_cli - k8s - kernelpkg - key - keyboard - kmod - locale - locate - log - logrotate - lowpkg - mandrill - match - mattermost - mine - minion - modjk - mount - msteams - nagios_rpc - namecheap_domains - namecheap_domains_dns - namecheap_domains_ns - namecheap_ssl - namecheap_users - netaddress - netmiko - network - nexus - nova - nxos_api - openscap - openstack_config - opsgenie - out - pagerduty - pagerduty_util - pam - parallels - peeringdb - pillar - pip - pkg - pkg_resource - publish - pushover - pyeapi - pyenv - random - random_org - rbenv - rest_sample_utils - ret - rvm - s3 - s6 - salt_proxy - saltcheck - saltutil - schedule - scp - scsi - sdb - seed - serverdensity_device - service - shadow - slack - slsutil - smbios - smtp - solrcloud - sqlite3 - ssh - state - status - statuspage - supervisord - sys - sysctl - sysfs - syslog_ng - system - telegram - telemetry - temp - test - textfsm - timezone - uptime - user - vault - vbox_guest - virtualenv - vsphere - xfs - zabbix - zenoss
Function: “list_functions”
Purpose: To get list of loaded functions
Function: “doc”
Argument: “module.function”
Purpose: To get the documentation of an appropriate function.
root@mrcissp-master-1:/# salt Router1 sys.doc net.arp net.arp: NAPALM returns a list of dictionaries with details of the ARP entries. :param interface: interface name to filter on :param ipaddr: IP address to filter on :param macaddr: MAC address to filter on :return: List of the entries in the ARP table CLI Example: salt '*' net.arp salt '*' net.arp macaddr='5c:5e:ab:da:3c:f0' Example output: [ { 'interface' : 'MgmtEth0/RSP0/CPU0/0', 'mac' : '5c:5e:ab:da:3c:f0', 'ip' : '172.17.17.1', 'age' : 1454496274.84 }, { 'interface': 'MgmtEth0/RSP0/CPU0/0', 'mac' : '66:0e:94:96:e0:ff', 'ip' : '172.17.17.2', 'age' : 1435641582.49 } ]