grains收集信息:
salt ‘*‘ grains.ls salt ‘web13*‘ grains.items 也可以单个显示 salt ‘*‘ grains.item fqdn salt ‘*‘ grains.item server_id salt ‘*‘ grains.get ip_interfaces:eth0
grains匹配minion
#比如查看所有centos的机器上执行uptime命令: salt -G os:centos cmd.run ‘uptime‘ web12.limingyu.com: 02:24:36 up 5:45, 1 user, load average: 0.06, 0.11, 0.08 web13.limingyu.com: 02:24:37 up 5:45, 1 user, load average: 0.19, 0.09, 0.06 #自定义grains: vim /etc/salt/minion #打下面几行 88 grains: 89 roles: 90 - webserver 91 - memcache 保存退出,重启minion /etc/init.d/salt-minion restart salt -G ‘roles:memcache‘ cmd.run ‘echo hehe‘ 或者 vim /etc/salt/grains web: nginx 保存退出,重启minion salt ‘*‘ grains.item web web12.limingyu.com: ---------- web: nginx web13.limingyu.com: ---------- web: salt -G web:nginx cmd.run ‘echo hehe‘ web12.limingyu.com: hehe
在top.sls里匹配:
vim /srv/salt/top.sls base: ‘web:nginx‘ : - match: grain - apache 保存,重启服务 salt -G web:nginx cmd.run ‘w‘
时间: 2024-10-13 20:42:15