Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

 
 

Using Salt to Copy Files to Devices Running Junos OS

Salt can manage a device running Junos OS through a proxy minion that establishes a NETCONF session over SSH with the device. When you use a proxy minion, you can’t use standard Salt functions to perform file copy operations on the device, because the device does not directly run the salt-minion process. The salt.modules.junos.file_copy execution function and the salt.states.junos.file_copy state function enable you to copy files from the Salt master or proxy minion server to the managed device running Junos OS.

junos.file_copy Function Syntax

The salt.modules.junos.file_copy execution function syntax is:

The salt.states.junos.file_copy state function syntax is:

where:

  • src—Source file’s path. To specify a path on the Salt master, use salt:// notation. To specify a path on the proxy minion server, use an absolute path.

  • dest—Destination file’s absolute or relative path on the device running Junos OS. If you do not specify an absolute path on the target device, the path is relative to the current working directory, which is the user’s home directory.

How to Copy Files with the junos.file_copy Execution Function

The junos.file_copy execution function enables you to quickly copy a file from the Salt master or proxy minion server to a device running Junos OS.

For example, the following command copies the bgp.slax file from the Salt master to the target device running Junos OS, router1, and renames the file to bgp-neighbors.slax:

Because the command does not specify an absolute path for the destination file, the file is copied to the home directory of the user.

To copy the file to a specific location, specify the absolute path on the target device.

How to Copy Files with the junos.file_copy State Function

You can use the junos.file_copy state function within a Salt state file to copy files from the Salt master or proxy minion server to a device running Junos OS. This enables you to store a master set of files in a single central repository and declare a state that defines which files to copy to a given minion. When you enforce or apply the state, Salt copies the necessary files from the repository to the device.

The following state file copies two scripts from /srv/salt/scripts/op directory on the Salt master server to the /var/db/scripts/op directory on the device running Junos OS:

When you apply the state to the target device, it copies each script to its specified location.

As another example, suppose you have a library of script files in the /srv/salt/scripts directory on the Salt master, and you want to ensure specific scripts are copied to the managed device running Junos OS.

On the Salt master, you can specify the script information as pillar data and make that accessible to the appropriate minions in the pillar top file, for example:

You can then create a Salt state file that uses a Jinja template to iterate over the script type and script name and generate the appropriate instructions to copy the scripts to the target devices.

Note:

Your Jinja syntax might vary depending on the version of Python that Salt uses.

The rendered state file becomes:

When you apply the state to the target device, it copies each script to the appropriate directory on the device for that script type.