Configuration management tools Saltstack custom Grains

Source: Internet
Author: User
Tags saltstack

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.