SaltStack - Using MinionFS as the File Server



The MinionFS is a special file server provided by Salt for the minions to exchange the files between them. The files served by the MinionFS are the files intentionally shared by minions. To share the files, a Minion has to follow steps given below.

  • Source minion has to push the file to the salt master using the cp.push function.

  • Once the files are pushed by the source minion, the deployed files can be accessed by any other minion using the MinionFS file server.

Enable Pushing

By default, pushing the files by minions to a master is disabled. To accept the files from minions, the master needs to have the “file_recv” option in the config file and its value must be set to True. By default, the value if “file_recv” is false.

file_recv: True

Once the option is enabled, restart the master service.

Pushing Files

Minions can push the files to the master. It is performed by the cp.push function. This cp.push function provides an easy mechanism to push the files by minion using the minion id.

salt 'minion-id' cp.push /path/to/the/file

Here, the minion-id is used to identify which minion is pushing the file. This command will store the file in a subdirectory named minions under the master's cachedir. Usually, the path is – /var/cache/salt/master/minions.

For minion, m1 and the file – /var/log/mylog.txt, the file will be stored in the – /var/cache/salt/master/minions/m1/var/log/mylog.txt.

Enable MinionFS

To enable the MinionFS, simply add minion in the fileserver backend setting as shown in the following code block.

fileserver_backend:
   - roots
   - minion

Once MinionFS is enabled, the minion pushed files are available as −

salt://<minion-id>/path/to/pushed/file

For minion, m1 and the pushed file – /var/log/mylog.txt, the pushed file will be served from salt://m1/var/log/mylog.txt.

This minionFS can be mounted in a special directory using the following configuration. It will separate the minionFS files from other files and will help in organizing the minion files.

minionfs_mountpoint: salt://minionfs

For the above configuration, the file will available under the minionfs directory as – salt://minionfs/m1/var/log/mylog.txt

MinionFS Advanced Options

The MinionFS also provides an option to enable / disable the availability of pushed files from a certain minion. The options are minionfs_whitelist, to enable minions and minionfs_blacklist, to disable the minions.

minionfs_whitelist:
   - webserver
   - develop*
   - ‘mail\d+.mysite.com'

minionfs_blacklist:
   - testing

In the above configuration, all minions except testing are allowed to share the file using minionFS.

  • Webserver1

  • Minions whose ids matches the regular expression develop *

  • Minions whose ids matches the regular expression mail\d+.mysite.com.

  • Testing

In the next chapter, we will learn how to use Cron with Salt.

Advertisements