Saltstack Basic Module Record two

Source: Internet
Author: User
Tags saltstack

One

Archive module

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

Example:

1, using Gunzip decompression sourcefile.txt.gz bag

Salt ' * ' Archive.gunzip sourcefile.txt.gz

2, using gzip compressed Sourcefile.txt file

Salt ' * ' Archive.gzip sourcefile.txt

3. API call:

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


Two

CMD module

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

Example:

1. Get the memory usage of the host to be controlled

Salt ' * ' cmd.run ' free-m '


2. Run the test.py script on the WX host, where script/test.py is stored in file_roots specified directory (by default in/srv/salt, custom defined in/etc/salt/master file),

#该命令会做2个动作: First sync test.py to minion cache directory; Get up and run the script

Salt ' wx ' cmd.script salt://script/test.py

3. API call:

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


Third, CP module

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

Example:

1. Copy the/etc/hosts file of the host to the local Salt cache directory (/var/cache/salt/minion/localfiles/) of the controlled host

Salt ' * ' cp.cache_local_file/etc/hosts

2, the host Terminal File_roots directory under the specified location to the host/minion/directory

Salt ' * ' Cp.get_dir salt://script//minion/

3. Copy the file under the specified location of the host terminal File_roots to the host/minion/test.py files (file is file name)

Salt ' * ' Cp.get_dir salt://script/test.py/minion/test.py

4, download the URL content to the host designated location (/tmp/index.html)

Salt ' * ' Cp.get_url http://www.slashdot.ort/tmp/index.html

5. API call:

Client.cmd (' * ', ' cp.get_file ', [' salt://script/test.py ', '/minion/test.py '])


Four

Cron Module

Function: Realize the crontab operation of the controlled host

Example:

1, view the designated host, root user crontab operation

Salt ' wx ' Cron.raw_cron root

2, the designated host, root user add/usr/local/weekly task Zuoye

Salt ' wx ' cron.set_job root ' * ' * ' * ' * ' 1/usr/local/weekly

3, in addition to the designated host, root user crontab/usr/local/weekly task Zuoye

Salt ' wx ' cron.rm_job root/usr/local/weekly

API calls:

Client.cmd (' wx ', ' cron.set_job ', [' root ', ' * ', ' * ', ' * ', ' * ', 1, '/usr/local/weekly ')


Five

Dnsutil Module

Function: To implement general DNS operation of the controlled host

Example:

1, plus specify host configuration items for host hosts

Salt ' wx ' dnsutil.hosts_append/etc/hosts 127.0.0.1 adl.yuk.com,ad2.yuk.com

2. Host configuration entries for hosts other than the hosts specified

Salt ' wx ' dnsutil.hosts_remove/etc/hosts ad1.yuk.com

API calls:

Clietn.cmd (' wx ', ' dnsutil.hosts_append ', ['/etc/hosts ', ' 127.0.0.1 ', ' ad1.yuk.com ', ' ad2.yuk.com ')


Six

File module

Function: Common file operation of the host, including file read and write, permission, find, check

Example:

1. Verify that the MD5 value of all host/etc/fstab files is xxxxxxxxxxxxx, and the true value is returned by consensus

Salt ' * ' File.check_hash/etc/fstab md5=xxxxxxxxxxxxxxxxxxxxx


1, verify all the host file encryption information, support MD5, SHA1, sha224, shs256, sha384, sha512 encryption algorithm

Salt ' * ' file.get_sum/etc/passwd MD5


2, change all the controlled host/etc/passwd file belonging to the group, user rights, equivalent to Chown root:root/etc/passwd

Salt ' * ' file.chown/etc/passwd root root


3, the control of all the host/PATH/TO/SRC files to the local/PATH/TO/DST file

Salt ' * ' FILE.COPY/PATH/TO/SRC/PATH/TO/DST


4. Check if all host hosts/etc directory exists, return True, check if file exists using File.file_exists method

Salt ' * ' file.directory_exists/etc


5, take all the controlled host/etc/passwd stats information

Salt ' * ' file.stats/etc/passwd


6, take all the controlled host/etc/passwd permissions mode, such as 755,644

Salt ' * ' file.get_mode/etc/passwd


7, change the permissions of all controlled host/etc/passwd mode is 0644

Salt ' * ' file.set_mode/etc/passwd 0644


8. Create/opt/test directory for all controlled hosts

Salt ' * ' file.mkdir/opt/test


9. The warn value of the loglevel parameter of all controlled host/etc/httpd/httpd.conf files is changed to info

Salt ' * ' file.sed/etc/httpd/httpd.conf ' LogLevel warn ' LogLevel info '


10, the host has been controlled/tmp/test/test.conf file append content ' maxclient 100 '

Salt ' * ' file.append/tmp/test/test.conf ' maxclient 100 '


11./tmp/foo files for all controlled hosts

Salt ' * ' File.remove/tmp/foo

API calls:

Client.cmd (' * ', ' file.remove ', ['/tmp/foo '])


Seven

Iptables module

Function: Iptables support for controlled host

Example:

1, all controlled host side append (append), insert iptables rule, where input is the input chain

Salt ' * ' iptables.append filter INPUT rule= '-m state--state related,established-j ACCEPT '

Salt ' * ' Iptables.insert filter INPUT position=3 rule= '-m state--state related,established-j ACCEPT '


2. All controlled hosts delete the specified chain number 3 (position=3) or specify a rule that exists

Salt ' * ' iptalbes.delete filter INPUT position=3

Salt ' * ' iptables.delete filter INPUT rule= '-m state--state relatec,established-j ACCEPT '


3, save all host-side host rules to local hard disk (/etc/sysconfig/iptables)

Salt ' * ' iptables.save/etc/sysconfig/iptables

API calls:

Client.cmd (' * ', ' iptables.append ', [' Filter ', ' INPUT ', ' rule=\ '-p tcp--sport 80-j accept\ '])

Eight

Network module

Function: Returns the network information of the controlled host

Example:

1, the designated host to obtain dig, ping, traceroute directory domain name information

Salt ' wx ' Network.dig www.qq.com

Salt ' wx ' network.ping www.qq.com

Salt ' wx ' Network.traceroute www.qq.com


2. Take the MAC address of the designated host

Salt ' wx ' network.hwaddr eth0


3, the test specifies whether the host is a 10.0.0.0/16 subnet range, belongs to return True

Salt ' wx ' network.in_subnet 10.0.0.0/16


4, take the designated host network card configuration information

Salt ' WX ' network.interfaces


5, take the designated host IP address configuration information

Salt ' WX ' Network.ip_addrs


6, take the designated host subnet information

Salt ' WX ' network.subnets

API calls:

Client.cmd (' wx ', ' Network.ip_addrs ')

Nine

PKG Package Management Module

Features: Managed host package management, e.g. Yum, apt-getdegn


Example:

1, all the Controlled host installation PHP environment, according to different system release call different installation tools for deployment, such as Redhat platform Yum, equivalent to yum-y install PHP

Salt ' * ' Pkg.install php


2. Download the PHP environment for all the hosts under control

Salt ' * ' pkg.remove php


3, level all the host package

Salt ' * ' Pkg.upgrade

API calls:

Client.cmd (' * ', ' pkg.remove ', [' php '])

Ten

Service Module

Function: Managed host Package Service management


Example:

1, start (enable), disable (disable) Nginx boot from the startup script

Salt ' * ' service.enable nginx

Salt ' * ' service.disable nginx

2, Reload, restart, start, stop, status operation for Nginx service

Salt ' * ' service.reload nginx

Salt ' * ' Service.restart nginx

Salt ' * ' Service.start nginx

Salt ' * ' service.stop nginx

Salt ' * ' service.status nginx


API calls:

Client.cmd (' * ', ' service.stop ', [' Nginx '])


Saltstack Basic Module Record two

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.