介绍salt为大家提供了从salt-master向salt-minion推送和拉取文件的“cp”模块
很好用呀
拉取文件
1
2
3
4
5
6
7
| [iyunv@ntest1 modules]# salt '*' cp.push /etc/rc.local
ntest3.dianjoy.com:
True
ntest1.dianjoy.com:
True
ntest2.dianjoy.com:
True
|
所有拉取的文件都保存在master节点的/var/cache/salt/master/minions/{minion-id}/files/etc/rc.local
1
2
| [iyunv@ntest1 modules]# salt '*' cp.push
/etc/system-release keep_symlinks=True
|
指定缓存文件到/var/cache/salt/master/minions/{minion-id}/new/path/fstab 1
2
| [iyunv@ntest1 modules]# salt '*' cp.push
/etc/fstab upload_path='/new/path/fstab'
|
1
2
| [iyunv@ntest1 modules]# salt '*' cp.push
/tmp/filename remove_source=True
|
1
2
| [iyunv@ntest1 modules]# salt '*' cp.push_dir
/etc/modprobe.d/ glob='*.conf'
|
下发文件1
2
3
4
5
| [iyunv@ntest1 prod]# salt 'ntest2.dianjoy.com' cp.cache_file
salt://jdk/files/jdk-7u71-linux-x64.tar.gz env=prod
ntest2.dianjoy.com:
/var/cache/salt/minion/files/prod/jdk/files/jdk-7u71-linux-x64.tar.gz
|
[iyunv@ntest1prod]# salt '*' cp.cache_filessalt://pathto/file1,salt://pathto/file1
1
2
3
4
5
6
| [iyunv@ntest1 ~]#
salt 'ntest2.dianjoy.com'
cp.cache_local_file /tmp/test.sh
ntest2.dianjoy.com:
/var/cache/salt/minion/localfiles/tmp/test.sh
|
1
2
3
4
5
6
7
| [iyunv@ntest1 ~]# salt 'ntest2.dianjoy.com'
cp.cache_master
ntest2.dianjoy.com:
-
/var/cache/salt/minion/files/base/zabbix/files/zabbix-mysql.conf
-
/var/cache/salt/minion/files/base/zabbix/files/zabbix_agentd.conf
|
1
2
3
4
5
6
7
8
| [iyunv@ntest1 ~]# salt 'ntest2.dianjoy.com' cp.get_dir
salt://init /tmp/
ntest2.dianjoy.com:
- /tmp//init/files/sshd_config
- /tmp//init/files/thrift-0.8.0.tar.gz
- /tmp//init/rsyslog.sls
- /tmp//init/ssh.sls
- /tmp//init/sysctl.sls
|
- 所有相同的系统在jinja模版作用下会下载相同的vimrc文件
1
2
| salt '*' cp.get_file
"salt://{{grains.os}}/vimrc" /etc/vimrc template=jinja
|
1
2
3
4
5
6
7
8
9
10
11
| [iyunv@ntest1
~]# salt 'ntest2.dianjoy.com'
cp.get_file_str salt://init/ssh.sls
ntest2.dianjoy.com:
sshd-config:
file.managed:
- name: /etc/ssh/sshd_config
- source: salt://init/files/sshd_config
- user: root
- group: root
- mode: 600
|
1
2
3
4
5
6
7
8
| [iyunv@ntest1 ~]#
salt '*' cp.get_url http://www.baidu.com/tmp/index.html
ntest2.dianjoy.com:
/tmp/index.html
ntest3.dianjoy.com:
/tmp/index.html
ntest1.dianjoy.com:
/tmp/index.html
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| salt '*'
cp.is_cached salt://init/ssh.sls
salt '*' cp.list_master
[iyunv@ntest1
~]# salt '*' cp.list_master_dirs
ntest1.dianjoy.com:
- .
- init
- init/files
- pillar
- pillar/zabbix
- salt
- salt/files
- zabbix
- zabbix/files
|
|