Minion side functions for salt-cp
salt.modules.cp.
cache_dir
(path, saltenv='base', include_empty=False, include_pat=None, exclude_pat=None, env=None)¶Download and cache everything under a directory from the master
Glob or regex to narrow down the files cached from the given path. If
matching with a regex, the regex must be prefixed with E@
,
otherwise the expression will be interpreted as a glob.
2014.7.0 新版功能.
Glob or regex to exclude certain files from being cached from the given
path. If matching with a regex, the regex must be prefixed with E@
,
otherwise the expression will be interpreted as a glob.
注解
If used with include_pat
, files matching this pattern will be
excluded from the subset of files defined by include_pat
.
2014.7.0 新版功能.
CLI范例:
salt '*' cp.cache_dir salt://path/to/dir
salt '*' cp.cache_dir salt://path/to/dir include_pat='E@*.py$'
salt.modules.cp.
cache_file
(path, saltenv='base', env=None)¶Used to cache a single file on the salt-minion Returns the location of the new cached file on the minion
CLI 范例:
salt '*' cp.cache_file salt://path/to/file
salt.modules.cp.
cache_files
(paths, saltenv='base', env=None)¶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 范例:
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 范例:
salt '*' cp.cache_local_file /etc/hosts
salt.modules.cp.
cache_master
(saltenv='base', env=None)¶Retrieve all of the files on the master and cache them locally
CLI 范例:
salt '*' cp.cache_master
salt.modules.cp.
get_dir
(path, dest, saltenv='base', template=None, gzip=None, env=None, **kwargs)¶Used to recursively copy a directory from the salt master
CLI 范例:
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, saltenv='base', makedirs=False, template=None, gzip=None, env=None, **kwargs)¶Used to get a single file from the salt master
CLI 范例:
salt '*' cp.get_file salt://path/to/file /minion/dest
模板渲染功能可以同时在源和目标文件启用,命名像这样:
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, saltenv='base', env=None)¶Return the contents of a file from a URL
CLI 范例:
salt '*' cp.get_file_str salt://my/file
salt.modules.cp.
get_template
(path, dest, template='jinja', saltenv='base', env=None, makedirs=False, **kwargs)¶Render a file as a template before setting it down. Warning, order is not the same as in fileclient.cp for non breaking old API.
CLI 范例:
salt '*' cp.get_template salt://path/to/template /minion/dest
salt.modules.cp.
get_url
(path, dest, saltenv='base', env=None)¶Used to get a single file from a URL.
The default behaviour is to write the fetched file to the given destination path. To simply return the text contents instead, set destination to None.
CLI 范例:
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, saltenv='base', env=None)¶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 范例:
salt '*' cp.hash_file salt://path/to/file
salt.modules.cp.
is_cached
(path, saltenv='base', env=None)¶Return a boolean if the given path on the master has been cached on the minion
CLI 范例:
salt '*' cp.is_cached salt://path/to/file
salt.modules.cp.
list_master
(saltenv='base', prefix='', env=None)¶List all of the files stored on the master
CLI 范例:
salt '*' cp.list_master
salt.modules.cp.
list_master_dirs
(saltenv='base', prefix='', env=None)¶List all of the directories stored on the master
CLI 范例:
salt '*' cp.list_master_dirs
salt.modules.cp.
list_master_symlinks
(saltenv='base', prefix='', env=None)¶List all of the symlinks stored on the master
CLI 范例:
salt '*' cp.list_master_symlinks
salt.modules.cp.
list_minion
(saltenv='base', env=None)¶List all of the files cached on the minion
CLI 范例:
salt '*' cp.list_minion
salt.modules.cp.
list_states
(saltenv='base', env=None)¶List all of the available state modules in an environment
CLI 范例:
salt '*' cp.list_states
salt.modules.cp.
push
(path, keep_symlinks=False, upload_path=None, remove_source=False)¶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/minion-id/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, set
file_recv
to True
in the master configuration file, and restart the
master.
Remove the source file on the minion
2016.3.0 新版功能.
CLI 范例:
salt '*' cp.push /etc/fstab
salt '*' cp.push /etc/system-release keep_symlinks=True
salt '*' cp.push /etc/fstab upload_path='/new/path/fstab'
salt '*' cp.push /tmp/filename remove_source=True
salt.modules.cp.
push_dir
(path, glob=None, upload_path=None)¶Push a directory from the minion up to the master, the files will be saved
to the salt master in the master's minion files cachedir (defaults to
/var/cache/salt/master/minions/minion-id/files
). It also has a glob
for matching specific files using globbing.
2014.7.0 新版功能.
Since this feature allows a minion to push files up to the master server it
is disabled by default for security purposes. To enable, set file_recv
to True
in the master configuration file, and restart the master.
CLI 范例:
salt '*' cp.push /usr/lib/mysql
salt '*' cp.push /usr/lib/mysql upload_path='/newmysql/path'
salt '*' cp.push_dir /etc/modprobe.d/ glob='*.conf'
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. It does not work via the CLI.