HomeAutomation Tools

DevOps | Automation | Salt SSH Adhoc Commands and Basics Modules

DevOps | Automation | Salt SSH Adhoc Commands and Basics Modules
Like Tweet Pin it Share Share Email
Personal Development Category (English)728x90

The previous article, we have explained introduction about Salt SSH and it’s basic usage. In this guide, you are going to see the next level of Salt SSH Adhoc Commands. Here we have some basic examples to understand the functionality of Salt Stack automation tool.

Also, Check out the Video for more details:

Salt SSH Adhoc Commands

Salt SSH Adhoc Commands and Basics ModulesSalt SSH Adhoc Commands

Command Syntax

# salt-ssh <target> <command> <arguments>

Let’s run the first salt command to test the connectivity with target minions

# salt-ssh -i ‘*’ test.ping  

Note – “*” means all minions/systems in the roaster.

You can select the individual target minions by have then command separated in the target.

# salt-ssh –L ‘appserver1,appserver2’ test.ping

Also, targets can be filtered by the regular expression:

# salt-ssh -E ‘appserver[1-2]’ test.ping

Salt SSH makes use of different modules to perform the operation on the target minions , below is example

Disk Module

# salt-ssh ‘*’ disk.usage

Pkg Module

# salt-ssh ‘*’ pkg.install httpd

Netwok Module

# salt-ssh ‘*’ network.interfaces

Salt SSH allows to run shell commands remotely on multiple target clients using cmd.run:

# salt-ssh ‘*’ cmd.run ‘uname -a;date;ifconfig -a‘

More Info on modules and their option: https://docs.saltstack.com/en/stage/ref/modules/all/index.html

The Salt States or SLS

Salt states are used to automate the system setup and configurations in the Infrastructure.

Command Syntax

# salt-ssh <target> state.<option> <state file>

In this demo we will use /etc/salt/master file , which is default configuration file for salt master. Uncomment below entries.


base: – /srv/salt/

You can create different base environments in the setup ..ex /srv/salt/dev or /srv/salt/prod

Grouping of minions of similar minions; similar functionality: /srv/salt/top.sls

base:                                    # Apply SLS files from the dir root for the ‘base‘env.

  ‘app*’:                               # All minions with servers that begins with app prefix

    – webserver                  # Apply the state file named ‘apache.sls‘

Sample State file to install httpd and start the service: /srv/salt/webserver.sls



   – installed

   – pkgs:

   – httpd


  – name: httpd

  – enable: True

Apply the state to the client machines/minions

# salt-ssh ‘app*’ state.apply webserver

Comments (1)

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.