salt '*' test.ping
salt '*' cmd.run "uptime"
salt 'salt-client.com' state.highstate -v test=True #测试
salt 'salt-client.com' state.highstate #主动推送
salt '*' sys.doc #查看哪些函数可用
salt '*' pkg.install vim #安装包 yum或apt
salt '*' network.interfaces #查看网络
检查存活主机
salt "*" test.ping #注意这里支持通配符哦,*表示所有,当然依旧也可以指定主机,在这里面test表示模块而ping则是方法。注意这里面的ping可不是Linux里面ICMP协议的ping是salt自己独有的东西
[iyunv@master ~]# salt "*" test.ping
salt-client.com:
True
命令执行
#查看磁盘利用率
salt "*" cmd.run "df -h"
#其中cmd为模块而run是方法df -h则是传入的参数.此时就能够返回各个主机的磁盘使用情况。cmd下的run方法后面可以接任何shell参数。因此这个模块非常之强大,当然也非常危险。
saltstack远程执行几个典型模块来学习:
SALT.MODULES.NETWORK
Module for gathering and managing network information
salt.modules.network.active_tcp()
CLI Example:
salt '*' network.active_tcp
salt.modules.network.arp()
Return the arp table from the minion
CLI Example:
salt '*' network.arp
SALT.MODULES.SERVICE
service is a virtual module that is fulfilled by one of the following modules:
salt.modules.service.available(name)
Returns True if the specified service is available, otherwise returns False.
CLI Example:
salt '*' service.available sshd
salt.modules.service.get_all()
Return a list of all available services
CLI Example:
salt '*' service.get_all
salt.modules.service.reload(name)
Refreshes config files by calling service reload. Does not perform a full restart.
CLI Example:
salt '*' service.reload
salt.modules.service.restart(name)
Restart the specified service
CLI Example:
salt '*' service.restart
SALT.MODULES.CP
Minion side functions for salt-cp
salt.modules.cp.cache_dir(path, saltenv='base', include_empty=False, include_pat=None, exclude_pat=None, env=None)
Download and cache everything under a directory from the master
CLI Example:
salt-cp '*’/etc/hots /opt/hehe
SALT.MODULES.STATE
Control the state system on the minion.
CLI Example:
salt '*' state.show_top
saltstack远程执行-返回程序
SALT.MODULES.MYSQL
Module to provide MySQL compatibility to salt.
说明:返回数据是指minion直接返回给MYSQL
salt.modules.mysql.db_create(name, character_set=None, collate=None, **connection_args)
Adds a databases to the MySQL server.
name
The name of the database to manage
character_set
The character set, if left empty the MySQL default will be used
collate
The collation, if left empty the MySQL default will be used
CLI Example:
salt '*' mysql.db_create 'dbname'
salt '*' mysql.db_create 'dbname' 'utf8' 'utf8_general_ci'
vim /_modules/my_disk.py
def list():
cmd = 'df-h'
ret = _salt_['cmd.run'](cmd)
return ret
3.刷新
#刷新命令会把文件放在/etc/salt/minion/extmods里面
salt '*' saltutil.sync_modules