saltstack-3 常用模块1

1、Archive

gzip压缩

salt '*' archive.gzip /tmp/try_test.txt

gzip解压缩

salt '*' archive.gunzip /tmp/try_test.txt

 

可以看到gzip打包后,源文件自动删除了。解压缩后,原本压缩文件也自动删除了。

 

 

2、cmd模块

salt '*' cmd.run 'free -m'

 

 3、cp模块

#复制被控机子的文件到/var/cache/salt/minion/localfiles
[root@zxw63 ~]# salt '*' cp.cache_local_file /tmp/try_test.txt
db_01:
    /var/cache/salt/minion/localfiles/tmp/try_test.txt
db_02:
    /var/cache/salt/minion/localfiles/tmp/try_test.txt

#切换db1,可以看到文件已经移动到相应目录下
[root@localhost ~]# ls -ltr /var/cache/salt/minion/localfiles/tmp/
total 0
-rw-r--r--. 1 root root 0 Aug 22 01:44 try_test.txt

复制master端file_roots下的文件和目录到minion端

复制文件夹及文件夹下的内容
salt '*' cp.get_dir salt://text_cp /tmp

 

复制文件
salt '*' cp.get_file salt://test_get.txt /tmp/get_file.txt

  复制文件时,需要指定到文件名字,不能指定到目录。

 

 4、cron模块

  • 添加任务
    salt "*" cron.set_job root '*' '*' '*' '*' 1 'echo "125"'

  • 删除任务
salt "*" cron.rm_job root 'echo "125"'

 

 5、dnsutil模块

  • 添加minion端hosts文件的内容
    salt '*' dnsutil.hosts_append /etc/hosts 127.0.0.1 ad1.zxw.com,ad2.zxw.com

  • 删除minion端hosts文件的内容
    salt '*' dnsutil.hosts_remove /etc/hosts ad1.zxw.com,ad2.zxw.com

     

6、file模块

对文件进行属性查看,内容更改,权组、权限更改等

salt '*' file.get_sum /etc/passwd md5获取文件的hash值
salt '*' file.check_hash /etc/passwd md5:90233857f150876cfc3e16c12266cd26检验文件的hash值
salt '*' file.mkdir /tmp/filecp新建文件夹
salt '*' file.copy /tmp/file_cp /tmp/filecp/filecp1复制文件
salt '*' file.directory_exists '/tmp/filecp'判断文件夹是否存在
salt '*' file.stats /etc/passwd获取文件状态
salt '*' file.get_mode /tmp/file_cp获取文件或文件夹权限
salt '*' file.set_mode /tmp/file_cp 0664根改文件权限
salt '*' file.append /tmp/file_cp "this is second append"追加文件内容

 

 

 

 

  

 

转载于:https://www.cnblogs.com/zxw-xxcsl/p/11394099.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值