Saltstack Python API call

Source: Internet
Author: User
Tags create directory saltstack

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

Related Article

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.