salt.modules.cp

Minion side functions for salt-cp

salt.modules.cp.cache_dir(path, env='base', include_empty=False)

Download and cache everything under a directory from the master

CLI Example:

salt '*' cp.cache_dir salt://path/to/dir
salt.modules.cp.cache_file(path, env='base')

Used to cache a single file in the local salt-master file cache.

CLI Example:

salt '*' cp.cache_file salt://path/to/file
salt.modules.cp.cache_files(paths, env='base')

Used to gather many files from the master, the gathered files will be saved in the minion cachedir reflective to the paths retrieved from the master.

CLI Example:

salt '*' cp.cache_files salt://pathto/file1,salt://pathto/file1
salt.modules.cp.cache_local_file(path)

Cache a local file on the minion in the localfiles cache

CLI Example:

salt '*' cp.cache_local_file /etc/hosts
salt.modules.cp.cache_master(env='base')

Retrieve all of the files on the master and cache them locally

CLI Example:

salt '*' cp.cache_master
salt.modules.cp.get_dir(path, dest, env='base', template=None, gzip=None)

Used to recursively copy a directory from the salt master

CLI Example:

salt '*' cp.get_dir salt://path/to/dir/ /minion/dest

get_dir supports the same template and gzip arguments as get_file.

salt.modules.cp.get_file(path, dest, env='base', makedirs=False, template=None, gzip=None)

Used to get a single file from the salt master

CLI Example:

salt '*' cp.get_file salt://path/to/file /minion/dest

Template rendering can be enabled on both the source and destination file names like so:

salt '*' cp.get_file "salt://{{grains.os}}/vimrc" /etc/vimrc template=jinja

This example would instruct all Salt minions to download the vimrc from a directory with the same name as their os grain and copy it to /etc/vimrc

For larger files, the cp.get_file module also supports gzip compression. Because gzip is CPU-intensive, this should only be used in scenarios where the compression ratio is very high (e.g. pretty-printed JSON or YAML files).

Use the gzip named argument to enable it. Valid values are 1..9, where 1 is the lightest compression and 9 the heaviest. 1 uses the least CPU on the master (and minion), 9 uses the most.

salt.modules.cp.get_file_str(path, env='base')

Return the contents of a file from a URL

CLI Example:

salt '*' cp.get_file_str salt://my/file
salt.modules.cp.get_template(path, dest, template='jinja', env='base', **kwargs)

Render a file as a template before setting it down

CLI Example:

salt '*' cp.get_template salt://path/to/template /minion/dest
salt.modules.cp.get_url(path, dest, env='base')

Used to get a single file from a URL.

CLI Example:

salt '*' cp.get_url salt://my/file /tmp/mine
salt '*' cp.get_url http://www.slashdot.org /tmp/index.html
salt.modules.cp.hash_file(path, env='base')

Return the hash of a file, to get the hash of a file on the salt master file server prepend the path with salt://<file on server> otherwise, prepend the file with / for a local file.

CLI Example:

salt '*' cp.hash_file salt://path/to/file
salt.modules.cp.is_cached(path, env='base')

Return a boolean if the given path on the master has been cached on the minion

CLI Example:

salt '*' cp.is_cached salt://path/to/file
salt.modules.cp.list_master(env='base')

List all of the files stored on the master

CLI Example:

salt '*' cp.list_master
salt.modules.cp.list_master_dirs(env='base')

List all of the directories stored on the master

CLI Example:

salt '*' cp.list_master_dirs
salt.modules.cp.list_minion(env='base')

List all of the files cached on the minion

CLI Example:

salt '*' cp.list_minion
salt.modules.cp.list_states(env='base')

List all of the available state modules in an environment

CLI Example:

salt '*' cp.list_states
salt.modules.cp.push(path)

Push a file from the minion up to the master, the file will be saved to the salt master in the master's minion files cachedir (defaults to /var/cache/salt/master/minions/files)

Since this feature allows a minion to push a file up to the master server it is disabled by default for security purposes. To enable add the option: file_recv: True to the master configuration and restart the master

CLI Example:

salt '*' cp.push /etc/fstab
salt.modules.cp.recv(files, dest)

Used with salt-cp, pass the files dict, and the destination.

This function receives small fast copy files from the master via salt-cp

CLI Example:

This function does not work via the CLI

Previous topic

salt.modules.config

Next topic

salt.modules.cron