Common commands

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

Remote script execution:

1
salt -N 'ceph' salt://scripts/runme.sh #Remote script execution

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 #The agent side pulls files from the master to /tmp
salt -N 'ceph' cp.get_file salt://files/opencdn/dir1/ /tmp #The agent side pulls directories from the master to /tmp
salt -N 'ceph' cp.get_url http://www.baidu.com /tmp/index.html #Download url
salt -N 'ceph' cp.push /etc/fstab #Extract the specified node file to the master, by default in the /var/cache/salt/master/minions/minion-id/files directory
salt -N 'ceph' cp.push_dir /etc/modprobe.d/ glob='*.conf' #Extract the specified configuration file of the node specified directory
salt-cp '*' fstab /etc/fstab #Copy the fstab file in the current directory to the node /etc/fstab
salt-cp -E 'gpu0[1-2][1-5]' fstab /etc/fstab #Regular matching copy file
salt-cp -G 'os:CentOS*' fstab /etc/fstab #grains matching copy file

Get disk information

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

File operation

1
2
3
salt -N 'ceph' file.chown /etc/passwd root root #Modify file permissions
salt -N 'ceph' file.copy /etc/passwd /tmp/passwd #Copy file
salt -N 'ceph' file.directory_exists /etc/passwd #Judge whether the file exists

User information operation

1
2
3
salt -N 'ceph' user.list_users #List all system accounts in the system
salt -N 'ceph' user.info lianghaiqiang #List user information
salt -N 'ceph' user.delete lianghaiqiang remove=True force=True #Force deletion of users

Time zone, restart, task plan

1
2
3
4
5
salt -N 'ceph' timezone.get_zone #Get time zone
salt -N 'ceph' timezone.set_zone #Set time zone
salt -N 'ceph' system.reboot #Reboot system
salt -N 'ceph' cron.list_tab root #List root scheduled tasks
salt -N 'ceph' cron.raw_cron root #List root scheduled tasks, text format

Unzip files:

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

Network

1
2
3
4
5
6
salt -N 'ceph' network.dig www.baidu.com #dig parsing
salt -N 'ceph' network.get_hostname #Get host name
salt -N 'ceph' network.hw_addr eth0 #Get MAC address
salt -N 'ceph' network.ip_addrs #Get IP address
salt -N 'ceph' network.ping www.baidu.com timeout=3 #ping information
salt -N 'ceph' pkg.install zlib #Install software package

Get object help information:

For example: grains/disk/pillar/pip/pkg

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
salt -N 'ceph' sys.doc sys #Get sys system help information
salt 'gpu054' sys.list_functions grains #Query grains attribute usage
salt 'gpu054' sys.doc grains #Query grains usage help
salt 'gpu054' sys.doc disk #Query disk usage help
salt 'gpu054' sys.list_functions pillar #Query pillar usage
salt 'gpu054' sys.doc pillar #Query pillar usage help
salt 'gpu054' pillar.item #Query pillar support data source
salt 'gpu054' sys.list_modules #Query minion support modules
salt 'gpu054' sys.list_functions pip #Query pip module support methods
salt 'gpu054' sys.doc pip #View pip module help
salt 'gpu054' sys.list_state_modules #Query all states list
salt 'gpu054' sys.list_state_functions pkg #Query pkg method
salt 'gpu054' sys.state_doc pkg #Query pkg help

Jobs management:

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