Salt file server: CP Module (III)

Source: Internet
Author: User

Salt file Server

The salt contains a simple file server for distributing files to salt minions. The file server is a stateless ZEROMQ server built on Salt master.

The primary intent of the Salt file server is to use the display file in the Salt State system. It appears that the salt file server can be used for any generic file transfer from Master to minions.

CP Module

The CP module is the home of Minion side file server operations. The CP module is used by the salt State system, SALT-CP, and can be used to distribute files presented by the salt file SE RVer.

1 Environment variables

Since The file server is made to work with the Salt state system, it supports environments. The environments is defined in the Master config file and then referencing an environment the file specified would be Based on the root directoryof the environment.

File_roots

Default:

Base:-/srv/salt

Salt runs a lightweight file server written in ZeroMQ to deliver files to minions. This file server is built to the master daemon and does not require a dedicated port.

The file server works on environments passed to the master. Each environment can has multiple root directories. The subdirectories in the multiple file roots cannot match, otherwise the downloaded files is not being able to be reliably Ensured. A base environment is required to house the top file.

Example:

Base:-/srv/salt Dev:-/srv/salt/dev/services-/srv/salt/dev/states prod:-/srv/salt/prod/services- /srv/salt/prod/states

Attention:

/srv/salt This path is the root of the salt and can be customized.

When you need to copy something, you need to put the file in this directory.

2 Get_file

The Cp.get_file feature can be used to download a file from master minion like this:

# salt ' * ' Cp.get_file SALT://VIMRC/ETC/VIMRC

The directive will notify all salt minions to download the VIMRC file and copy it to/ETC/VIMRC

eg

Master

[Email protected]/]# du-s/srv/salt/boot_bak.tar.gz
48272/srv/salt/boot_bak.tar.gz

[Email protected]/]# MV boot_bak.tar.gz/srv/salt/

[[email protected]/]# Salt ' * ' Cp.get_file Salt://boot_bak.tar.gz/tmp/boot.bak
CENTOS_MINION_01:
/tmp/boot.bak

Minion:

[Email protected] tmp]# Ll/tmp/boot.bak
-rw-r--r--. 1 root root 49429171 Jan 07:54/tmp/boot.bak

[Email protected] tmp]# du-s/tmp/boot.bak
48272/tmp/boot.bak


The template rendering feature can be enabled in both the source and destination files, named like this:

# salt ' * ' Cp.get_file "SALT://{{GRAINS.OS}}/VIMRC"/ETC/VIMRC Template=jinja

This example will notify all salt minions downloads VIMRC downloaded from the same name as their OS grain and copied to/ETC/VIMRC

large file transfers, which can be compressed using gzip, Rating: 1--9:

For larger files, the Cp.get_file module also supports gzip compression. Because gzip cpu-intensive, this should only be used in scenarios where the compression ratio is very high (e.g. pretty -printed JSON or YAML files).

To use compression, use the gzip named argument. Valid values is integers from 1 to 9, where 1 is the lightest compression and 9 the heaviest. In other words, 1 uses the least CPU on the master (and Minion), while 9 uses the most.

# salt ' * ' Cp.get_file SALT://VIMRC/ETC/VIMRC gzip=5
makedirs: Automatically create a Minion-side folder when a folder does not exist

Finally, note this by the default Cp.get_file does not create new destination directories if they does not exist. To change this, use the makedirs argument:

# salt ' * ' Cp.get_file SALT://VIMRC/ETC/VIM/VIMRC makedirs=true

In this example,/etc/vim/would is created if it didn ' t already exist.

3 Get_dir

The Cp.get_dir function can be used in the Minion to download a entire directory from the master. The syntax is very similar to Get_file:

# salt ' * ' Cp.get_dir salt://etc/apache2/etc

Cp.get_dir supports template rendering and gzip compression arguments just like get_file:

# salt ' * ' Cp.get_dir Salt://etc/{{pillar.webserver}}/etc gzip=5 Template=jinja
eg

master:

[[email protected] salt]# du-s lib/             
242460    lib/

Cp-a/lib.

Salt ' * ' Cp.get_dir salt://lib/tmp-v

Minion:

[Email protected] tmp]# du-s lib/
242460 lib/



Reference Path:
http://docs.saltstack.cn/zh_CN/latest/ref/file_server/index.html

This article is from the "Tiandaochouqin" blog, make sure to keep this source http://luzhi1024.blog.51cto.com/8845546/1735170

Salt file server: CP Module (III)

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.