Salt master Configuration
Cat /etc/salt/master| grep ' # ' 192.168auto_accept:true file_roots: Base: -/data/salt/ Base
The custom grains has two methods, the first minion-side configuration, but requires the restart Minion to take effect, the second is configured on the master side, takes effect after synchronization, does not need to restart Master or minion
This example customizes the grains with the master end of the second method
Create the _grains directory under the Salt Base (/data/salt/base) directory, under the _grains directory nginx.py
#!/usr/bin/env python#Coding:utf-8#define Nginx configuration files, logs, and other informationImportOs,commandsdefnginx (): Grains={} grains['Nginx_bin'] = Commands.getoutput ("ps-ef | grep nginx |grep master| grep-v grep |awk ' {print $ (NF-2)} '"). Split ('\ n') grains['nginx_conf'] = Commands.getoutput ("ps-ef |grep nginx |grep Master | grep-v grep |awk ' {print $ (NF)} '"). Split ('\ n') Nginx_dir=[] Nginx_log= [] forFilesinchgrains['Nginx_bin']: Nginx_dir.append (Os.path.dirname (Os.path.dirname (Files)) Nginx_log.append (Os.path.dirname (Os.path.dirnam E (files))+'/logs/access.log') grains['Nginx_dir'] =Nginx_dir grains['Nginx_log'] =Nginx_logreturnGrainsif __name__=='__main__': Nginx ()
Synchronizing and viewing grains information for a definition
# Salt 192.168 .xxx.xxx saltutil.sync_grains 192.168 .xxx.xxx: - Grains.nginx
192.168 . xxx.xxx grains.item nginx_conf nginx_log nginx_bin 192.168 . Xxx.xxx: ---------- nginx_bin: -/data/prg/nginx-magicube/sbin/nginx -/data/prg/ tengine-play10/sbin/nginx nginx_conf: -/data/prg/nginx-magicube/conf/nginx.conf -/data/prg/tengine-play10/conf/nginx.conf nginx_log: -/data/prg/ nginx-magicube/logs/access.log -/data/prg/tengine-play10/logs/access.log
You can see that the defined Grains.nginx entry is already in effect
Configuration management tools Saltstack custom Grains