Introduction
Salt is a powerful configuration management and remote execution tool. It allows users to manage the configuration of multiple servers from a central location using a declarative configuration language. With Salt, users can easily manage the installation of software and system packages, manage user accounts and permissions,etc.

File Servers is a general term for servers that are used to deliver files to various clients. We can also do this in Salt by configuring our Salt Master to deliver files to various Salt Minion nodes. This blog will show File Servers in Salt, how to set them up, and how we can use them to deliver files across Salt minions. Let's get started.
CP Module
Salt can act as a file server for the minions. This means we can configure our Salt Master to serve files to all the minions in our Salt network. For this, we use the CP Module.
The CP module is the module that handles fetching files from the Salt file servers that we will set up.
Make sure you have Salt Master configured and at least one Salt Minion. If you don't, you can check out how to install it here – Salt Install Guide.
Let us see the basic setup needed to ensure the CP module runs correctly.
Basic Setup
Generally, if you have already used Salt for some task, you would have already done this. If you are just starting, this step might not have been completed yet. The following lines need to be added to the master configuration file.
file_roots:
base:
- /srv/salt
- /srv/formulas
The master config file is located in the /etc/salt folder, and it is named master.
To navigate to the correct directory, enter the following command in the terminal.
cd /etc/salt
Then, to open the nano editor, type the command:
sudo nano master
You can also use vim or any other editor of your choice. Sudo needs to be added if you don't have direct access to edit the file.

After adding the lines shown in the image above, if we ask Salt to look for the file "test.txt", it will look in the /srv/salt folder in the Salt Master. If it doesn't find it there, it will then look in the /srv/formulas folder. If it isn't present there either, then Salt will be unable to deploy the file to the minions.
cp.get_file
cp.get_file is the basic command of the cp module. It looks for a file and, if found, sends it to the minions.
Let's say we have a file ninja.txt in the/srv/salt folder of the Salt Master machine.

The file contains simple text data - "Hello Ninja!"
Our minion machine does not contain any files. We can verify it here.

Now, let's run the cp.get_file command on Salt Master. It should be run as:
sudo salt '*' cp.get_file salt://ninja.txt ~/ninja.txt
-
Sudo is entered to give salt access to the file and permission to copy it. Depending on your user's privileges, you might not need to enter sudo.
-
* specifies that this file should be copied to all Salt Minions. If we only wanted to copy it to a particular minion, we should have written its name instead.
-
salt://ninja.txt is a salt URL. This tells Salt to look under the file servers we have set up. We will see why we couldn't just write a simple file path in the File Servers Backend section of this blog.
- ~/ninja.txt is the output directory. It tells Salt where Salt should place this file on the minion machines.

We have only one Minion machine, and it has returned an output. It prints the location of the new file. If the file was not found, there would have been no output.
Let's check on the minion machine.

We can see the empty output has been replaced with a ninja.txt file.

It also has the correct data.
cp.get_dir
cp.get_dir command is used to send a whole directory to minion nodes.
Let's say we have a directory ninja_folder, with two files ninjaFile1.txt and ninjaFile2.txt.

These are the files, and their contents.
Let's deploy them to minion nodes.
Type the command:
sudo salt '*' cp.get_dir salt://ninja_folder ~/saltFiles

Salt has created a new folder saltFiles on our minion node. It has copied the ninja_folder into the saltFiles folder, along with both files inside it. Let's verify it in our minion machine.

We can see folder has been copied correctly, and the files have the correct data.












