salt.modules.cp.get_dir(path, dest, saltenv='base', template=None, gzip=None, env=None)
Used to recursively copy a directory from the salt master
1、复制目录
salt '*' cp.get_dir salt://path/to/dir/ /minion/dest
从主节点的能访问到的URL处复制文件给从节点
salt.modules.cp.get_url(path, dest, saltenv='base', env=None)
Used to get a single file from a URL.
The default behaviuor is to write the fetched file to the given destination path. To simply return the text contents instead, set destination to None.
CLI Example:
salt '*' cp.get_url salt://my/file /tmp/mine
salt '*' cp.get_url http://www.slashdot.org /tmp/index.html
2、主节点访问的URL下载到从节点
举例
1
2
3
4
5
6
7
[iyunv@master nginx]# salt 'test1' cp.get_url http://www.05hd.com/wp-content/u ... ginx-init-CentOS.sh /tmp/nginx-init-beta1.sh
test1:
/tmp/nginx-init-beta1.sh
从节点
[iyunv@localhost tmp]# ll
total 11048
-rw-r--r-- 1 root root 2541 Dec 30 13:59 nginx-init-beta1.sh
3、把从节点的文件拷到主节点
1
2
3
4
[iyunv@localhost tmp]# ll -lh | grep Python-2.7.6.tar.xz
-rw-rw-r-- 1 centos centos 10M Dec 21 16:53 Python-2.7.6.tar.xz #把这个文件拷到主节点主节点并无此tar包
2014-12-30 15:16:02,753 [salt.loaded.int.module.cp ][ERROR ] cp.push Failed transfer failed. Ensure master has 'file_recv' set to
'True' and that the file is not larger than the 'file_recv_size_max' setting on the maste
# Allow minions to push files to the master. This is disabled by default, for
# security purposes.
#file_recv: False 这里为False并非是True修改需要重读配置文件甚至重启服务。
# Set a hard-limit on the size of the files that can be pushed to the master.
# It will be interpreted as megabytes.
# Default: 100
#file_recv_max_size: 100 #默认为100M
修改完了后尝试重读配置文件
[iyunv@master salt]# service salt-master reload
can't reload configuration, you have to restart it
#看来上面推测错误了不需要重读重启服务吧。
重读取时的错误
1
2
3
4
5
6
7
in "<string>", line 212, column 1:
file_recv:True
^
could not found expected ':'
in "<string>", line 213, column 1:
# Set a hard-limit on the size o ...
^
报错的原因就是因为file_recv:True中间应该有一个空格
修改以后再次重启服务。主节点执行
1
2
3
4
5
[iyunv@master salt]# salt 'test1' cp.push /tmp/Python-2.7.6.tar.xz
test1:
True
让我们看看这个Python的tar包被放在哪了
/var/cache/salt/master/minions/test1/files/tmp/Python-2.7.6.tar.xz
#可以看出被缓存下来了
仔细看配置文件原来
# Directory to store job and cache data
cachedir: /var/cache/salt/master #在这里定义了
4、把从节点的目录拷贝到主节点。
官方的解释
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.
New in version 2014.7.0.
主节点使用命令salt 'test1' cp.push_dir /tmp/ glob='*.*' #把从节点的tmp目录下的所有文件拷贝到主节点
一会儿可以查看复制完成了。