加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

saltstack-3 常用模块1

发布时间:2020-12-14 00:10:53 所属栏目:Linux 来源:网络整理
导读:1、Archive gzip压缩 salt ‘ * ‘ archive. gzip /tmp/try_test.txt gzip解压缩 salt ‘ * ‘ archive. gunzip /tmp/try_test.txt ? ‘ 可以看到gzip打包后,源文件自动删除了。解压缩后,原本压缩文件也自动删除了。 ? ? 2、cmd模块 salt ‘ * ‘ cmd.run

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
[[email?protected] ~]# 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,可以看到文件已经移动到相应目录下
[[email?protected] ~]# 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" 追加文件内容

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读