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