自定義grains_module pillar

轉載於:http://blog.liuts.com/page/1/1/

自定義grains_module
1)#vi /srv/salt/_grains/nginx_config.py

view plainprint?

  1. import os,sys,commands  

  2.   

  3. def NginxGrains():  

  4.     ''' 

  5.         return Nginx config grains value 

  6.     '''  

  7.     grains = {}  

  8.     max_open_file=65536  

  9.     #Worker_info={'cpus2':'01 10','cpus4':'1000 0100 0010 0001','cpus8':'10000000 01000000 00100000 00010000 00001000 00000100 00000010 00000001'}  

  10.     try:  

  11.         getulimit=commands.getstatusoutput('source /etc/profile;ulimit -n')  

  12.     except Exception,e:  

  13.         pass  

  14.     if getulimit[0]==0:  

  15.         max_open_file=int(getulimit[1])  

  16.     grains['max_open_file'] = max_open_file  

  17.     return grains  


2)同步grains模塊
salt '*' saltutil.sync_all

3)刷新模塊(讓minion編譯模塊)
salt '*' sys.reload_modules

4)驗證max_open_file key的value
[root@SN2013-08-020 _grains]# salt '*' grains.item max_open_file              
SN2013-08-022:
  max_open_file: 1024
SN2013-08-021:
  max_open_file: 1024
SN2012-07-011:
  max_open_file: 1024
SN2012-07-012:
  max_open_file: 1024
SN2012-07-010:
  max_open_file: 1024

配置pillar
    本例使用分組規則定義pillar,即不同分組引用各自的sls屬性
1)定義入口top.sls
#vi /srv/pillar/top.sls

  1. base:  

  2.   web1group:  

  3.     - match: nodegroup  

  4.     - web1server  

  5.   web2group:  

  6.     - match: nodegroup  

  7.     - web2server  


2)定義私有配置,本例只配置web_root的數據,當然可以根據不同需求進行定製,格式爲python的字典形式,即"key:value"。
#vi /srv/pillar/web1server.sls 

  1. nginx:  

  2.     root: /www  


#vi /srv/pillar/web2server.sls 

  1. nginx:  

  2.     root: /data  


3)驗證配置結果:
#salt 'SN2013-08-021' pillar.data nginx
SN2013-08-021:
    ----------
    root:
        /data

#salt 'SN2012-07-010' pillar.data nginx 
SN2012-07-010:
    ----------
    root:
        /www


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章