.
The
salt:// url format can potentially contain a query string, for example
salt://dir/file.txt?saltenv=base. You can prevent the fileclient/fileserver from
interpreting
? as the initial token of a query string by referencing the file
with
salt://| rather than
salt://.
/etc/marathon/conf/?checkpoint: file.managed: - source: salt://|hw/config/?checkpoint - makedirs: True instance is available which allows for modules and applications 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.
The
salt/fileclient.py module is used to set up the communication from the
minion to the master. When creating a client instance 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:
import salt.minion import salt.fileclient def get_file(path, dest, saltenv='base'): ''' Used to get a single file from the Salt master CLI Example: salt '*' cp.get_file salt://vimrc /etc/vimrc ''' # Get the fileclient object client = salt.fileclient.get_file_client(__opts__) # Call get_file return client.get_file(path, dest, False, saltenv)
Creating a fileclient instance outside of a minion module where the
__opts__
data is not available, it needs to be generated:
import salt.fileclient import salt.config def get_file(path, dest, saltenv='base'): ''' Used to get a single file from the Salt master ''' # Get the configuration data opts = salt.config.minion_config('/etc/salt/minion') # Get the fileclient object client = salt.fileclient.get_file_client(opts) # Call get_file return client.get_file(path, dest, False, saltenv)