Linux saltstack常用模块

所有模块

  salt '172.30.100.126' sys.list_modules  #列出当前版本支持的模块

  salt '*' sys.doc cp  #显示指定模块的文档

archive模块

  实现系统层面的压缩包调用,支持gzip、gunzip、rar、tar、unrar、unzip等

cmd模块

  实现远程的命令行调用执行

salt '*' cmd.run 'df -h'
# 执行传递的命令,并将结果作为字符串返回
salt '*' cmd.script salt://tmp/test.sh
# 从master端下载脚本,并在本地执行

cp模块

  实现远程文件、目录的复制,以及下载URL文件等操作

salt '*' cp.get_dir salt://path/to/dir/ /minion/dest
# 从master递归复制指定目录到minion目录下
salt '*' cp.get_file salt://path/to/file /minion/file
从master复制单个文件到minion
salt '*' cp.push /etc/hosts
# 把minion端的文件推送到master端
# 存放目录默认在/var/cache/salt/master/minions/minion-id/files
salt '*' cp.push /usr/lib/mysql
# 从minion端推送一个目录到master端

cron模块

  实现被控主机的crontab操作

salt '*' cron.raw_cron root
# 返回指定用户的cron内容
salt '*' cron.set_job root '*' '*' '*' '*' 1 /usr/local/weekly
# 为指定用户添加一条cron任务
salt '*' cron.rm_job root /usr/local/weekly
# 为指定用户删除一条cron任务

file模块

salt '*' file.chown /etc/passwd root root
# 修改文件的属主属组
salt '*' file.copy /path/to/src /path/to/dst
salt '*' file.copy /path/to/src_dir /path/to/dst_dir recurse=True remove_existing=True
# 从src复制文件或目录到dst,可以递归复制,可以存在删除
salt '*' file.move /path/to/src /path/to/dst
# 移动指定文件或目录
salt '*' file.rename /path/to/src /path/to/dst
# 修改指定文件或目录的名称
salt '*' file.file_exists /etc/hosts
salt '*' file.directory_exists /etc
# 检查指定文件或目录是否存在
salt '*' file.stats /etc/hosts
# 返回指定文件或目录的stats信息
salt '*' file.mkdir /tmp/test
# 不存在则创建,确保目录存在
salt '*' file.remove /tmp/foo
# 删除指定文件,如果是目录将被递归删除

  

猜你喜欢

转载自www.cnblogs.com/hyc-blog/p/10136784.html