First, Python installation saltstack
Pip Install salt
Second, the interface invocation instance
1, test.ping
Import Salt.client
Client = Salt.client.LocalClient ()
ret = client.cmd (' * ', ' test.ping ')
Print ret
2. CMD module
1) Function: Implement call execution of remote command
2) Example:
Get memory usage for all hosts salt ' * ' Cmd.run "free-m"
Client.cmd (' sn2016-02-04 ', ' cmd.run ', [' free-m '])
3. CP Module
1) Functions: Remote file replication, directory replication, and download URL files and other operations
2) Example:
Copy the/etc/hosts file for the controlled host to the local Salt cache directory (/var/cache/salt/minion/localfiles) of the managed host
Salt ' * ' cp.cache_local_file/etc/hosts
Copy the primary server File_roots directory under the specified location to the managed host
Salt ' * ' Cp.get_dir salt://path/to/dir/minion/dest
Copy the primary server file_roots files from the specified location to the managed host
Salt ' * ' Vcp.get_file salt://path/to/file/minion/dest
Download URL content to the designated host location
Salt ' * ' Cp.get_url http://www.saltshdot.org/tmp/index.html
Client.cmd (' xn2016-02-04 ', ' cp.get_file ', [' salt://path/to/file ', '/minion/dest '])
4. File module
1) Function: Common operation of controlled host files
2) Example
Verifies whether the MD5 of the/ETC/PADDWD file for all managed hosts is lkhwln423lkn4l23kjh42l3j4ml, and the same returns ture
Salt ' * ' file.check_hash/etc/passwd md5=lkhwln423lkn4l23kjh42l3j4ml
Create directory on all managed hosts
Salt ' * ' file.mkdir/opt/test
Change the warn of the loglevel parameter of the/etc/httpd/httpd.conf file of all controlled hosts to info
Salt ' * ' file.sed/etc/httpd/httpd.conf ' LogLevel warn ' LogLevel info '
Append content ' Maxclient 1000 ' to all/tmp/test/test.conf files of the controlled host
Salt ' * ' file.append/tmp/test/test.conf ' maxclient 1000 '
Delete all/etc/foo files for the managed host
Salt ' * ' File.remove/etc/foo
Client.cmd (' * ', ' file.remove ', ['/etc/foo '])
This article is from the "My Ops Time" blog, so be sure to keep this source http://aaronsa.blog.51cto.com/5157083/1741165
Saltstack Python API call