saltstack学习3模块

module

查看所有的module列表
[root@master ~]# salt '*' sys.list_modules
node1:
    - acl
    - aliases
    - alternatives
...
查看指定module的所有function
[root@master ~]# salt '*' sys.list_functions
查看指定module的所有用法列表
[root@master ~]# salt '*' sys.list_functions cmd
node1:
...
    - cmd.retcode
    - cmd.run
...
查看指定module的指定用法的介绍
[root@master ~]# salt '*' sys.doc cmd.run
cmd.run:
...
        salt '*' cmd.run cmd='sed -e s/=/:/g'

常用的module

看官方文档https://docs.saltproject.io/en/latest/ref/modules/all/

network service cmd cp pkg cron dnsutil

pkg
# salt '*' pkg.install nmap
# salt '*' pkg.file_list nmap
network
[root@master ~]# salt '*' network.connect www.baidu.com 80
master:
    ----------
    comment:
        Successfully connected to www.baidu.com (14.215.177.38) on tcp port 80
    result:
        True
node1:
    ----------
    comment:
        Successfully connected to www.baidu.com (14.215.177.38) on tcp port 80
    result:
        True
service
[root@master ~]# salt '*' service.available sshd
node1:
    True
[root@master ~]# salt '*' service.get_all
node1:
    - NetworkManager
    - NetworkManager-dispatcher
...
[root@master ~]# salt '*' service.restart httpd
[root@master ~]# salt '*' service.run postgresql
[root@master ~]# salt '*' service.reload postgresql       #status stpp
cp模块
# salt '*' cp.get_dir salt://hellotest  /data
# salt '*' cp.get_file salt://hellotest/test.txt /root/test.txt
# salt '*' cp.get_url http://*.com/download/files.tgz /root/files.tgz
cron模块
为指定的被控主机、root用户添加crontab信息
# salt '*' cron.set_job root '*/5' '*' '*' '*' '*' 'date >/dev/null 2>&1'
# salt '*' cron.raw_cron root
## 删除指定的被控主机、root用户的crontab信息
# salt '*' cron.rm_job root 'date >/dev/null 2>&1'
# salt '*' cron.raw_cron root
cmd模块
salt '*' cmd.run "ls -l | awk '/foo/{print $2}'"
salt '*' cmd.exec_code python2 'print("hello world")'
salt '*' cmd.script salt://scripts/runme.sh 'arg1 arg2 "arg 3"'
file模块
# salt '*' file.get_sum /etc/resolv.conf md5
# salt '*' file.stats /etc/resolv.conf
nginx模块

批量操作nginx服务器

salt '*' nginx.configtest
salt '*' nginx.signal reload
salt '*' nginx.status
salt '*' nginx.version

states

#查看state的列表
[root@master ~]# salt '*' sys.list_state_modules
...
   - file
#查看指定state的函数
[root@master ~]# salt '*' sys.list_state_functions file
node1:
    - file.absent
    - file.accumulated
    - file.append
#查看指定state的用法
[root@master ~]# salt '*' sys.state_doc  file.append

https://www.cnblogs.com/davygeek/p/7754207.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值