Open source softwares - SaltStack

Back to Course

Lesson Description

Lession - #1527 Salt File Server

Salt comes with a simple train server suitable for distributing files to the Salt minions. The file server is a stateless ZeroMQ server that's built into the Salt master.

The main intent of the Salt file server is to present files for use in the Salt state system. With this said, the Salt file server can be used for any general file transfer from the master to the minions.


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 lines presented by the Salt file server.


The swab// url format can potentially contain a query string, for illustration salt//dir/file.txt? saltenv = base. You can help the fileclient/ fileserver from interpreting? as the initial token of a query string by representing the file with salt//| rather than salt//.

 etc/ marathon/ conf/? checkpoint 
- source salt//| hw/ config/? checkpoint 
- makedirs True 


Since the file server is made to work with the Salt state system, it supports surroundings. The surroundings are defined in the master config file and when representing an environment the file specified will be based on the root directory of the environment.

Thecp.get_file function can be used on the minion to download a file from the master, the syntax looks like this

salt' *'cp.get_file salt// vimrc/ etc/ vimrc

This will instruct all Salt minions to download the vimrc file and copy it to etc/ vimrc

Template picture can be enabled on both the source and destination file names like so

salt' *'cp.get_file" salt//{{grains.os}} vimrc" etc/ vimrc template = jinja

This illustration would instruct all Salt minions to download the vimrc from a directory with the same name as their zilches grain and copy it to etc/ vimrc

For larger files, thecp.get_file module also supports gzip contraction. Because gzip is CPU- ferocious, this should only be used in scripts where the compression ratio is very high(e.g. enough- published JSON or YAML files>

To use compression, use the gzip named argument. Valid values are 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 

Eventually, note that by defaultcp.get_file doesn't create new destination directories if they don't exist. To change this, use the makedirs argument

 salt' *'cp.get_file salt// vimrc/ etc/ vim/ vimrc makedirs = True 

In this illustration, etc vim/ would be created if it did not formerly exist.

Thecp.get_dir function can be used on the minion to download an entire directory from the master. The syntax is very similar toget_file

 salt' *'cp.get_dir salt// etc/ apache2/ etc 
 supports template rendering and gzip contraction arguments just likeget_file 
 salt' *'cp.get_dir salt// etc/{{pillar.webserver}} etc gzip = 5 template = jinja 


A customer instance is available which allows for modules and operations to be written which make use of the Salt file server.

The file server uses the same authentication and encryption used by the rest of the Salt system for network communication.


Thesalt/fileclient.py module is used to set up the communication from the minion to the master. When creating a client case using the fileclient module, the minion configuration needs to be passed in. When using the fileclient module from within a minion module the built in, opts, data can be passed