salt master配置
# cat /etc/salt/master|grep -v ‘#‘ interface: 192.168.xxx.xxx worker_threads: 15 auto_accept: True file_roots: base: - /data/salt/base
自定义grains有两种方法,第一种minion端配置,但是需要重启minion生效;第二种在master端配置,同步之后生效,不需要重启master或者minion
本例以第二种方法master端自定义grains
在salt base (/data/salt/base)目录下创建_grains目录,在 _grains目录下nginx.py
#!/usr/bin/env python #coding:utf-8 #定义nginx配置文件、日志等信息 import os,commands def nginx(): 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 = [] for files in grains[‘nginx_bin‘]: nginx_dir.append(os.path.dirname(os.path.dirname(files))) nginx_log.append(os.path.dirname(os.path.dirname(files)) + ‘/logs/access.log‘) grains[‘nginx_dir‘] = nginx_dir grains[‘nginx_log‘] = nginx_log return grains if __name__ == ‘__main__‘: nginx()
同步并查看定义的grains信息
# salt 192.168.xxx.xxx saltutil.sync_grains 192.168.xxx.xxx: - grains.nginx
# salt 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
可以看到定义的grains.nginx项已经生效
时间: 2024-12-04 19:52:19