Saltstack-salt Common modules and APIs

Source: Internet
Author: User
Tags gz file certbot saltstack

Salt provides a very rich set of functional modules, covering the basic functions of the operating system, common tool support, etc., you can list the modules supported by the current version through the SYS module.

Salt ' * ' sys.list_modules781915e2:-Acl-aliases-alternatives-apache-archive-artifactory-at-blockdev-btrfs -Buildout-cloud-cmd ...


The API principle is implemented by invoking the Master client module, instantiating a Localclient object, and then invoking the cmd () method.

API Implementation Test.ping Example:

>>> Import salt.client>>> client = Salt.client.LocalClient () >>> ret = client.cmd (' * ', ' Test.ping ') >>> print ret{' 781915e2 ': True} #结果以一个标准的Python字典形式的字符串返回, can be converted to a Python dictionary type through the eval () function, Facilitate subsequent business logic processing


(1) Archive module

Function: Implement the system level compression package call, support Gunzip, gzip, RAR, tar, Unrar, unzip and so on.

Example:

Salt ' 781915e2 ' cmd.run ' mkdir/opt/test ' #为被控端minion创建/opt/test directory 781915e2:scp test.txt.gz [email protected]:/opt/te St #将测试的gzip文件拷贝给被控端minionsalt ' 781915e2 ' archive.gunzip/opt/test/test.txt.gz #解压被控端/opt/test/test.txt.gz file 781915e 2:salt ' 781915e2 ' archive.gzip/opt/test/test.txt #压缩781915e2:

API calls:

>>> Import salt.client>>> client = Salt.client.LocalClient () >>> client.cmd (' * ', ' Archive.gunzip ', ['/opt/test/test.txt.gz ']) {' 781915e2 ': []}


(2) CMD module

Function: Implement remote command line call execution (default root operation, need to evaluate risk when using)

Example:

[[email protected] ~]# salt  ' * '  cmd.run  ' free -m ' 781915e2:                  total        used       free      shared    buffers     cached    mem:            996         834        162           0        121         252    -/+ buffers/cache:        460         536    Swap:             0          0           0

API calls:

Client.cmd (' * ', ' cmd.run ', [' free-m])


(3) CP module

Functions: Remote file, directory replication, download URL files and other operations.

Example:

salt  ' * '  cp.cache_local_file /etc/hosts       #将指定被控主机的/etc/hosts files to the Salt cache directory that is local to the host (/var/cache/salt/minion/localfiles) 781915e2:  /var/cache/salt/minion/localfiles/etc/hosts salt  ' * '  cp.get_dir salt://path/to/dir/  /minion/dest     #将主服务器file_roots指定位置下的目录复制到被控主机,salt://  First '/' for   The root of the configuration file base, and the second is the path delimiter 781915e2:    salt  ' * '  cp.get_file salt://path/to/file  /minion/dest    #将主服务器file_roots指定位置下的文件复制到被控主机781915e2:    salt  ' * '  cp.get_url http://www.baidu.com /tmp/index.html     # Download URL content to the host specified location 781915e2:    /tmp/index.html 

API calls:

Client.cmd (' * ', ' cp.get_file ', [' salt://path/to/file ', '/minion/dest '])


(4) Cron module

Function: Realize the crontab operation of the controlled host

Example:

salt  ' * '  cron.raw_cron root      #查看指定被控主机, root user crontab listing 781915e2:      #secu-tcs-agent monitor, install at sat mar 18  15:55:40 cst 2017    * * * * * /usr/local/sa/agent/ secu-tcs-agent-mon-safe.sh /usr/local/sa/agent > /dev/null 2>&1     */1 * * * * /usr/local/qcloud/stargate/admin/start.sh > /dev /null 2>&1 &    */20 * * * * /usr/sbin/ ntpdate ntpupdate.tencentyun.com >/dev/null &    30 2 *  * * /www/server/panel/certbot-auto renew >> /www/server/panel/logs/ certbot.log    salt  ' * '  cron.set_job root  ' * '   ' * '   ' * '   ' * '  1 /USR/LOCAL/WEEKLY   #为指定的被控主机, root user Add/usr/local/weekly task job 781915e2:    newsalt  ' 789880e2 '   cron.rm_job root /usr/local/weekly      #删除指定的被控主机, root user crontab/usr/local/ Weekly Task Job 781915e2:    removed

API calls:

Client.cmd (' * ', ' cron.set_job,[' root ', ' * ', ' * ', ' * ', ' * ', ' * ', '/usr/echo '))












This article is from the "Shei" blog, make sure to keep this source http://kurolz.blog.51cto.com/11433546/1934033

Saltstack-salt Common modules and APIs

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.