saltstack cp模块使用

cp模块

在配置管理系统中,从中心服务器向客户端推送文件是很基本的需求。SaltStack使用内建的ZeroMQ服务器作为文件服务器。 文件服务器主要用来在state系统中推送文件到客户端,也能够用于其余文件的传输。html

cp模块

客户端对文件服务器的操做都在cp模块中。Salt State系统,
也可以使用Salt-cp代替mysql

基本解释:

salt根目录:在master中 file_roots 定义的路径
例如:假设在master中有以下定义:
file_roots:
base:web

  • /srv/salt/
    那么:salt://vimrc指的实际路径是:/srv/salt/vimrc,这样作的好处是,能够知足state系统中环境的概念。sql

常见用法:

get_file:
master下载文件到客户端:
salt ‘*’ cp.get_file salt://vimrc /etc/vimrc
salt ‘*’ cp.get_file “salt://`grains`.`os`/vimrc” /etc/vimrc template=jinja   使用模板
salt ‘*’ cp.get_file salt://vimrc /etc/vimrc gzip=5 压缩:其中,1表明做小压缩,9表明最大压缩。
salt ‘*’ cp.get_file salt://vimrc /etc/vim/vimrc makedirs=True 若是目录不在,则建立目录
注意:cp.get_file默认不在客户端上创建目录,若是客户端上没有这个目录,且未指定makedirs=True,文件拷贝将失败。apache

get_dir

从master下载整个目录:
salt ‘*’ cp.get_dir salt://etc/apache2 /etc
salt ‘*’ cp.get_dir salt://etc/`pillar`.`webserver` /etc gzip=5 template=jinja 也支持模板和压缩vim

get_url

从一个URL地址下载文件,URL能够是msater上的路径(salt://),也能够是http网址。
salt ‘*’ cp.get_url salt://my/file /tmp/mine
salt ‘*’ cp.get_url http://www.slashdot.org /tmp/index.html安全

get_template

在文件下载以前用模板引擎处理。
salt ‘*’ cp.get_template salt://path/to/template /minion/destbash

push

从客户端传文件到master上,处于很明显的安全考虑,默认没有启用此功能,若是你须要的话能够参考文档,很方便的开启。服务器

其余&例子:

1.        salt '*' cp.cache_dir salt://path/to/dir
2.        salt '*' cp.cache_dir salt://path/to/dir include_pat='E@*.py$'
3.        salt '*' cp.cache_file salt://path/to/file
4.        salt '*' cp.cache_files salt://pathto/file1,salt://pathto/file1
5.        salt '*' cp.cache_local_file /etc/hosts
6.        salt '*' cp.cache_master
7.        salt '*' cp.get_dir salt://path/to/dir/ /minion/dest
8.        salt '*' cp.get_file salt://path/to/file /minion/dest
9.        salt '*' cp.get_file "salt://`grains`.`os`/vimrc" /etc/vimrc template=jinja
10.        salt '*' cp.get_file_str salt://my/file
11.        salt '*' cp.get_template salt://path/to/template /minion/dest
12.        salt '*' cp.get_url salt://my/file /tmp/mine
13.        salt '*' cp.get_url http://www.slashdot.org /tmp/index.html
14.        salt '*' cp.hash_file salt://path/to/file
15.        salt '*' cp.is_cached salt://path/to/file
16.        salt '*' cp.list_master
17.        salt '*' cp.list_master_dirs
18.        salt '*' cp.list_master_symlinks
19.        salt '*' cp.list_minion
20.        salt '*' cp.list_states
21.        salt '*' cp.push /etc/fstab
22.        salt '*' cp.push /etc/system-release keep_symlinks=True
23.        salt '*' cp.push /usr/lib/mysql
24.        salt '*' cp.push_dir /etc/modprobe.d/ glob='*.conf'
相关文章
相关标签/搜索