????Saltstack????????puppet??func???????????л?????????saltstack????python?????????????????????????????????????????????????????????????????????????????????????????????????????????saltstack?????????л??????ù?????????Nginx??????????????漰salt??grains??grains_module??pillar??States??jinja??template??????????????salt?????????????
????????豸???????
??????????web??????????????????web1group??web2group???豸??????á?web??????????.
????id    groupsnode  cpus webroot
????SN2012-07-010 web1group  2  /www
????SN2012-07-011 web1group  4  /www
????SN2012-07-012 web1group  2  /www
????SN2013-08-021 web2group  2  /data
????SN2013-08-022 web2group  2  /data
????id groupsnode cpus webroot
????SN2012-07-010 web1group 2 /www
????SN2012-07-011 web1group 4 /www
????SN2012-07-012 web1group 2 /www
????SN2013-08-021 web2group 2 /data
????SN2013-08-022 web2group 2 /data
????????master???????
????1???????????壺
????nodegroups: 
????web1group: 'L@SN2012-07-010??SN2012-07-011??SN2012-07-012' 
????web2group: 'L@SN2013-08-021??SN2013-08-022' 
????file_roots: 
????base: 
????- /srv/salt 
????pillar_roots: 
????base: 
????- /srv/pillar
????nodegroups: 
????web1group: 'L@SN2012-07-010??SN2012-07-011??SN2012-07-012' 
????web2group: 'L@SN2013-08-021??SN2013-08-022' 
????file_roots: 
????base: 
????- /srv/salt 
????pillar_roots: 
????base: 
????- /srv/pillar
????2??????????????


?????????????grains_module
????1??#vi /srv/salt/_grains/nginx_config.py
????import os??sys??commands 
????def NginxGrains(): 
????'''
????return Nginx config grains value
????''' 
????grains = {} 
????max_open_file=65536 
????#Worker_info={'cpus2':'01 10'??'cpus4':'1000 0100 0010 0001'??'cpus8':'10000000 01000000 00100000 00010000 00001000 00000100 00000010 00000001'} 
????try: 
????getulimit=commands.getstatusoutput('source /etc/profile;ulimit -n') 
????except Exception??e: 
????pass 
????if getulimit[0]==0: 
????max_open_file=int(getulimit[1]) 
????grains['max_open_file'] = max_open_file 
????return grains
????import os??sys??commands 
????def NginxGrains(): 
????'''
????return Nginx config grains value
????''' 
????grains = {} 
????max_open_file=65536 
????#Worker_info={'cpus2':'01 10'??'cpus4':'1000 0100 0010 0001'??'cpus8':'10000000 01000000 00100000 00010000 00001000 00000100 00000010 00000001'} 
????try: 
????getulimit=commands.getstatusoutput('source /etc/profile;ulimit -n') 
????except Exception??e: 
????pass 
????if getulimit[0]==0: 
????max_open_file=int(getulimit[1]) 
????grains['max_open_file'] = max_open_file 
????return grains
????2)???grains???
????# salt '*' saltutil.sync_all
????1
????# salt '*' saltutil.sync_all
????3)??????(??minion???????)
????# salt '*' sys.reload_modules
????1
????# 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
????[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
????base: 
????web1group: 
????- match: nodegroup 
????- web1server 
????web2group: 
????- match: nodegroup 
????- web2server
????base: 
????web1group: 
????- match: nodegroup 
????- web1server 
????web2group: 
????- match: nodegroup 
????- web2server
????2)?????????????????????web_root?????????????????????????ж????????python????????????"key:value"??
????#vi /srv/pillar/web1server.sls
????nginx: 
????root: /www 
????#vi /srv/pillar/web2server.sls
????nginx: 
????root: /data
????#vi /srv/pillar/web1server.sls
????nginx: 
????root: /www 
????#vi /srv/pillar/web2server.sls
????nginx: 
????root: /data
????3????????y????
????#salt 'SN2013-08-021' pillar.data nginx
????SN2013-08-021:
????----------
????root:
????/data
????#salt 'SN2012-07-010' pillar.data nginx
????SN2012-07-010:
????----------
????root:
????/www
????#salt 'SN2013-08-021' pillar.data nginx
????SN2013-08-021:
????----------
????root:
????/data
????#salt 'SN2012-07-010' pillar.data nginx
????SN2012-07-010:
????----------
????root:
????/www
?????塢????States
????1?????????top.sls
????#vi /srv/salt/top.sls
????base: 
????'*': 
????- nginx
????1
????2
????3
????4
????#vi /srv/salt/top.sls
????base: 
????'*': 
????- nginx
????2)????nginx???ü????????SLS??????salt://nginx/nginx.conf???????????λ?á?
????#vi /srv/salt/nginx.sls
????view plainprint?
????nginx: 
????pkg: 
????- installed 
????file.managed: 
????- source: salt://nginx/nginx.conf 
????- name: /etc/nginx/nginx.conf 
????- user: root 
????- group: root 
????- mode: 644 
????- template: jinja 
????service.running: 
????- enable: True 
????- reload: True 
????- watch: 
????- file: /etc/nginx/nginx.conf 
????- pkg: nginx
????#vi /srv/salt/nginx.sls
????view plainprint?
????nginx: 
????pkg: 
????- installed 
????file.managed: 
????- source: salt://nginx/nginx.conf 
????- name: /etc/nginx/nginx.conf 
????- user: root 
????- group: root 
????- mode: 644 
????- template: jinja 
????service.running: 
????- enable: True 
????- reload: True 
????- watch: 
????- file: /etc/nginx/nginx.conf 
????- pkg: nginx