231312111 发表于 2016-12-12 09:50:41

SaltStack使用教程(五):命令拉取和推送文件

介绍salt为大家提供了从salt-master向salt-minion推送和拉取文件的“cp”模块
很好用呀
拉取文件

[*]默认是禁止从minion拉取文件到master,需要修改 file_recv: True才能拉取文件

1
2
3
4
5
6
7
# 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
# salt '*' cp.push
/etc/system-release keep_symlinks=True






[*]下面是2016版本最新功能
指定缓存文件到/var/cache/salt/master/minions/{minion-id}/new/path/fstab
1
2
# salt '*' cp.push
/etc/fstab upload_path='/new/path/fstab'






[*]拉取文件后,删除minion上的原文件

1
2
# salt '*' cp.push
/tmp/filename remove_source=True






[*]拉取目录

1
2
# salt '*' cp.push_dir
/etc/modprobe.d/ glob='*.conf'





下发文件
[*]缓存单文件到minion端

1
2
3
4
5
# 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






[*]指定多文件
# salt '*' cp.cache_filessalt://pathto/file1,salt://pathto/file1

[*]操作minion缓存minion本地的文件

1
2
3
4
5
6
#
salt 'ntest2.dianjoy.com'
cp.cache_local_file /tmp/test.sh
ntest2.dianjoy.com:
   
/var/cache/salt/minion/localfiles/tmp/test.sh






[*]推送master上的全部文件到minion

1
2
3
4
5
6
7
#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






[*]推送master上目录到minion

1
2
3
4
5
6
7
8
#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






[*]查看salt项目下的文件

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





[*]使用url推送文件

1
2
3
4
5
6
7
8
#
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






页: [1]
查看完整版本: SaltStack使用教程(五):命令拉取和推送文件