Saltstack common modules and APIs (4)

Source: Internet
Author: User
Tags saltstack

Saltstack provides a very rich set of functional modules (written in Python), covering the basic functions of the operating system, common tool support, and, of course, the SYS module to list the modules supported by the current version

#salt ' * ' Sys.list_modules


Next, the common modules are introduced, and the API usage methods of the modules are also enumerated. The API principle is implemented by invoking the Master client module, instantiating a Localclient object, and then invoking the Cmda () method. The following is an example of an API implementation test.ping:

Import Salt.client

Client = Salt.client.LocalClient ()

ret = client.cmd (' * ', ' test.ping ')

Print ret


The results are returned in a standard Python dictionary form, and can be converted to a Python dictionary type using the eval () function to facilitate subsequent business logic processing, which results in the following program operation:

{' sn2013-08-022 ': true, ' sn2013-08-021 ': true}


(1) Archive module

Function: Implementation of system-level compression package calls, support Gunzip, gzip, RAR, tar, unrar, unzip, etc.

Example:

Salt ' * ' archive.gunzip/tmp/sourcefile.txt.gz with gunzip decompression/tmp/sourcefile.txt.gz pack

Salt ' * ' archive.gzip/tmp/sourcefile.txt with gzip compressed/tmp/sourcefile.txt file

API Invocation Principle:

Client.cmd (' * ', ' archive.gunzip ', ['/tmp/sourcefile.txt.gz '])


(2) CMD module

Function: Implement remote command-line execution

Example:

Salt ' * ' Cmd.run "free-m" for all host memory conditions

Salt ' * ' cmd.script salt://script/test This command will do two actions: first synchronize test.sh to Minion's cache directory (/var/cache/salt/minion/files/base/ SCRIPT/TEST.SH); Run the script next

API Invocation Principle:

Client.cmd (' sn2013-08-021 ', ' cmd.run ', [' free-m '])


(3) CP module

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

Example:

The Salt ' * ' cp.cache_local_file/etc/hosts copies the/etc/hosts file of the specified minion to the local Salt cache directory of the Minion host (/var/cache/salt/ minion/localfiles/)

Salt ' * ' cp.get_dir salt://path/to/dir//minion/dest Copy the directory under the File_roots specified location on the master to minion

Salt ' * ' cp.get_url http://www.slashdot.org/tmp/index.html download URL content to minion at the specified location

API Invocation Principle:

Clientcmd (' sn2013-08-021 ', ' cp.get_file ', [' salt://path/to/file ', '/minion/dest '])


(4) Cron module

Function: Realize the crontab operation of minion

Example:

Salt ' sn2013-08-022 ' Cron.raw_cron root view crontab list of specified minion and root users

Salt ' sn2013-08-022 ' cron.set_job root ' * ' * ' * ' * ' * ' 1/usr/local/weekly Add job task for specified minion, root user

Salt ' sn2013-08-022 ' cron.rm_job root/usr/local/weekly Delete crontab task job for Minion, root user/usr/local/weekly

API Invocation Principle:

Client.cmd (' sn2013-08-022 ', ' cron.set_job ', [' Root, ' * ', ' * ', ' * ', ' * ', ' * ', '/usr/echo '])


(5) Dnsutil module

Function: Implement minion host general DNS related operation

Example:

Salt ' * ' dnsutil.hosts_append/etc/hosts 127.0.0.1 ad1.yuk.com,ad2.yuk.com Add hosts host configuration entry

Salt ' * ' dnsutil.hosts_remove/etc/hosts ad1.yuk.com Delete hosts host configuration entry

API Invocation Principle:

Client.cmd (' * ', ' dnsutil.hosts_append ', ['/etc/hosts ', ' 127.0.0.1 ', ' ad1.yuk.com '])


(6) File module

Function: Implement Minion Host file common operation, including file read/write, permission, find, check etc.

Example:


API Invocation Principle:


(7) Archive module

Function:

Example:

API Invocation Principle:


(8) Archive module

Function:

Example:

API Invocation Principle:


(9) Archive module

Function:

Example:

API Invocation Principle:


(10) Archive module

Function:

Example:

API Invocation Principle:



Saltstack common modules and APIs (4)

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.