Common Commands

1
2
3
4
5
6
7
8
9
salt -N 'ceph' test.ping                     # Test connectivity
salt -E '^server10*' test.ping                # Match by regex for connectivity
salt -S 192.168.150.101 test.ping             # Match by agent IP address
salt -S 192.168.150.0/24 test.ping            # Match by IP subnet
salt -N 'ceph' cmd.run 'df -Th'              # Check disk usage by group
salt -N 'ceph' cmd.exec_code python 'import os; print os.system("df -Th")'  # Execute Python code
salt -N 'ceph' cmd.exec_code perl 'print scalar localtime'  # Execute Perl code
salt -G 'osrelease:6.3' cmd.run 'python -V'   # Filter by grains and execute
salt '*' smbios.get system-serial-number      # Get server hardware serial number

Remote Script Execution:

1
salt -N 'ceph' salt://scripts/runme.sh  # Execute script remotely

Remote File Copy:

1
2
3
4
5
6
7
8
salt -N 'ceph' cp.get_file salt://files/opencdn/a.txt /tmp/a.txt     # Pull file from master to agent
salt -N 'ceph' cp.get_file salt://files/opencdn/dir1/ /tmp           # Pull directory from master to agent
salt -N 'ceph' cp.get_url http://www.baidu.com /tmp/index.html       # Download URL
salt -N 'ceph' cp.push /etc/fstab                                   # Push file from minion to master (default: /var/cache/salt/master/minions/minion-id/files)
salt -N 'ceph' cp.push_dir /etc/modprobe.d/ glob='*.conf'          # Push specific config files from directory
salt-cp '*' fstab /etc/fstab                                         # Copy local fstab file to target node
salt-cp -E 'gpu0[1-2][1-5]' fstab /etc/fstab                        # Copy via regex match
salt-cp -G 'os:CentOS*' fstab /etc/fstab                             # Copy via grains match

Disk Information

1
2
3
salt -N 'ceph' disk.percent /data01        # Get disk usage percentage
salt -N 'ceph' disk.nodeusage /data01      # Get inode usage
salt -N 'ceph' xfs.info /data01            # Get XFS partition info

File Operations

1
2
3
salt -N 'ceph' file.chown /etc/passwd root root    # Change file ownership
salt -N 'ceph' file.copy /etc/passwd /tmp/passwd   # Copy file
salt -N 'ceph' file.directory_exists /etc/passwd   # Check if file exists

User Management

1
2
3
salt -N 'ceph' user.list_users         # List all system users
salt -N 'ceph' user.info lianghaiqiang  # Show user details
salt -N 'ceph' user.delete lianghaiqiang remove=True force=True  # Force delete user

Timezone, Reboot, and Cron

1
2
3
4
5
salt -N 'ceph' timezone.get_zone        # Get timezone
salt -N 'ceph' timezone.set_zone        # Set timezone
salt -N 'ceph' system.reboot            # Reboot system
salt -N 'ceph' cron.list_tab root       # List root's cron jobs
salt -N 'ceph' cron.raw_cron root       # List root's cron jobs in raw text format

File Extraction & Compression

1
2
3
salt -N 'ceph' archive.cmd_unzip template=jinja /tmp/zipfile.zip /tmp/{{grains.id}}/ excludes=file_1,file_2
salt -N 'ceph' archive.cmd_unzip /tmp/zipfile.zip /home/strongbad/ excludes=file_1,file_2
salt -N 'ceph' archive.cmd_zip template=jinja /tmp/zipfile.zip /tmp/sourcefile1,/tmp/{{grains.id}}.txt

Networking

1
2
3
4
5
6
salt -N 'ceph' network.dig www.baidu.com     # DNS lookup
salt -N 'ceph' network.get_hostname          # Get hostname
salt -N 'ceph' network.hw_addr eth0          # Get MAC address
salt -N 'ceph' network.ip_addrs              # Get IP addresses
salt -N 'ceph' network.ping www.baidu.com timeout=3  # Ping with timeout
salt -N 'ceph' pkg.install zlib               # Install package

Get Help on Objects:

e.g., grains/disk/pillar/pip/pkg

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
salt -N 'ceph' sys.doc sys                  # Get system help
salt 'gpu054' sys.list_functions grains      # List available grains functions
salt 'gpu054' sys.doc grains                 # View grains documentation
salt 'gpu054' sys.doc disk                   # View disk module documentation

salt 'gpu054' sys.list_functions pillar       # List pillar functions
salt 'gpu054' sys.doc pillar                  # View pillar documentation
salt 'gpu054' pillar.item                     # List supported pillar data sources

salt 'gpu054' sys.list_modules                # List available minion modules
salt 'gpu054' sys.list_functions pip          # List pip module functions
salt 'gpu054' sys.doc pip                     # View pip module help

salt 'gpu054' sys.list_state_modules          # List all state modules
salt 'gpu054' sys.list_state_functions pkg    # List pkg state functions
salt 'gpu054' sys.state_doc pkg               # View pkg state help

Job Management:

1
2
3
4
salt-run jobs.active                          # View active jobs on all minions (running saltutil.running)
salt-run jobs.lookup_jid <jid>                # Query results for a specific JID from master job cache
salt-run jobs.list_jobs                       # List all current jobs in master job cache
salt 'xxxx' saltutil.kill_job <jid>           # Kill a job on the master