Using Salt API to Deploy Files From/to Custom Targets in SystemLink

Updated Feb 19, 2024

Environment

Software

  • SystemLink Server

Other

  • Salt

This article outlines a few commands of the Salt API, that gets installed with SystemLink and that you can leverage to move files between SystemLink server and clients. It is meant to be used in situations where the SystemLink File API fails to meet the flexibility that might be required in specific cases; you can still leverage the File API along with these methods, these just provide additional ways to move files.
This article leverages a third-party service, you can find more information about this topic in Salt Project.

1. Set the File Moving path in SystemLink Server Configuration to the default (*) Salt Master path: C:\ProgramData\National Instruments\salt\srv\salt.
2. Use any of the following approaches where these commands can be executed from this path C:\Program Files\National Instruments\Shared\salt-master (or this one C:\Program Files\National Instruments\Shared\salt-minion depending on the command) or the same calling the corresponding batch file in those directories.
 

Run salt-cp command on the SystemLink server side to copy files into minion(s)


This command will copy the indicated file to a specific location for one or multiple targets. You can indicate what target specifically to copy the files to or you can use expressions or other filters to copy the file to multiple targets. You can also copy the file to all minions at once using "*".

Examples:

salt-cp * File.txt Targetdirectory

this would attempt to copy the file (File.txt located in C:\ProgramData\National Instruments\salt\srv\salt) to all minions on which the Targetdirectory exists (RT targets and Windows clients have different root directories)

salt-cp minionID FilesToCopy\File.txt Targetdirectory

This one will copy File.txt that lives inside the directory C:\Program Files\National Instruments\Shared\salt-master\FilesToCopy to the target with the specified minionID and into the Targetdirectory.

salt-cp -E PartialMinionID-[0-5] ..\File.txt Targetdirectory

This will copy File.txt located in the directory C:\Program Files\National Instruments\Shared to all targets that match the provided expression being in this case an almost equal minionID that ends on "-[numbers from 0 to 5]", this is just an example, but you can build more relevant target expressions according to your use case if needed.

Note: Using this command to copy files to an RT target, causes the copied file to take the name of the absolute path of the original file. In the last example, if it was copying to an RT target, the resulting file name would be: C:\Program Files\National Instruments\Shared\File.txt
 

Run salt.modules.cp.get_file on minions to instruct them to pull files


This command can be executed from this directory for Window clients C:\Program Files\National Instruments\Shared\salt-minion. It works similarly to the previous one and can be used to get a single file from the server.

Example:

salt * cp.get_file salt://..\File.txt Targetdirectory

This would be very similar to the previous example, but it will try to copy the files to all minions. You can also change the * for a minionID if you want to copy to a specific target.

When copying files to an RT target, the copied file takes the name of the relative path used in the command. For example, the file name in the last example would end up as "..\File.txt". This means that if you use this option with files located in the master root path then the files will have the expected name.
 

Create a new state using the salt.states.file module and specify the files that should be transferred to minions
 

Recursive directory management can allow grouping files into directories, one for each minion or any similar setting. Then you can deploy the state to clients. This alternative is very flexible, and it does not result in any naming oddities for RT minions. This alternative is focused on copying directories instead of single files. So, if you create new directories each containing specific files you may then run a command to copy the entire content of the directory. These are the associated steps to implement this alternative:

  1. Create a Salt State file (*.sls) and place it in this directory C:\ProgramData\National Instruments\salt\srv\salt, for example:
 

copyfiles.sls.png
 

Where the name token is the TargetDirectory and source is the relative location of the directory to copy (relative to this path: C:\ProgramData\National Instruments\salt\srv\salt)

  2. Run a command to execute the *.sls file operation, the command is executed from the same path as the previous ones (C:\Program Files\National Instruments\Shared\salt-master)

For example:

salt minionID state.sls copyfiles

This executes the operation shown in the previous screenshot (the copyfiles.sls file), copying the CopyTest directory content to the /home/test directory for the target with the given minionID.

This means you could have different *.sls files for your different copies and then just call them with a command to execute the copy of all the files from a specific directory to a specific location.




Additionally, you can use the systems management HTTP API to create salt jobs. In this example the WebVI uses the system management HTTP API and salt jobs to read log files from a target.