Salt-grains&pillar

Source: Internet
Author: User

One, grains 

Grains: This is the same as Puppet's Facter function. Mainly responsible for collecting some basic information of the client, this is also fully customizable, can be customized in the client, and then automatically report up, you can also from the server-side definition and push down, after the acquisition, and then report up grains information is static; pillar and grains compare his flexibility, Define that definition, and then take the value.

Usage of grains:

1[email protected] ~]# salt' *'Grains.items # #查询所有的grains信息2Test1:3----------4 SSDs:5 biosreleasedate:6          ,/ -/ -7 biosversion:8 A1TSA1A9 Cpu_flags:Ten-FPU One-VME A-de --PSE --TSC the-MSR --PAE --MCE --cx8 +-APIC --Sep +-MTRR A-PGE at-MCA --Cmov --Pat --Pse36 --Clflush --DTS in-ACPI --MMX to-FXSR +-SSE --SSE2 the-SS *-HT $-TMPanax Notoginseng-PBE --Syscall the-NX +-PDPE1GB A-RDTSCP the-LM +-CONSTANT_TSC --Arch_perfmon $-PEBs $-BTS --Rep_good --xtopology the-NONSTOP_TSC -n lines are omitted here ..... .......
1 ' 10.13.41.21 ' grains.get Ip_interfaces:eth0 # #查询eth0所用IP地址 2 10.13. 41.21 : 3     10.13. 41.21 4     -Fe80::72e2:84ff:fe12:7a05

Add custom items using grains

 The first method:

On the Minion side:Modify the configuration file/etc/salt/minion open default_include:minion.d/*.conf

Add items that need to be added in the/etc/salt/minion.d/directory, and the file type corresponds to the configuration item *.conf
1 Cat  2grains:  3     4  test:yes  5   OA:  6     - a  7     - b
Then restart the Minion service/etc/init.d/salt-minion restart to see if the add succeeds on the master side
1[email protected] ~]# salt'10.13.41.21'Grains.items2 10.13.41.21:3----------4 ITEMS:5         Ten6 OA:7-a8-b9 SSDs:Ten TEST: OneTrue # #表示成功

The second method:

Add on Master side, create _grains directory in/srv/salt/, write grains file, need to return a dictionary
1 pwd 2 /srv/salt/_grains3cat4def nginx ():5   nginx={}6   nginx['nginx']='  1.5.5' # #定义nginx的默认版本 7   return Nginx
8 Sync to minion side: Salt ' * ' state.highstate
  

Two, Pillar  

Pillar is a very important component of salt, which is used to define any data you need for a specific minion, which can be used by other components of the salt. Salt introduced Pillar in version 0.9.8. Pillar after parsing is completed, is a nested dict structure; the topmost key is the Minion ID whose value is the Pillar data owned by the Minion, and each value is key/value. Here you can see a feature of Pillar, Pillar data is associated with a specific minion, that is, each minion can only see their own data, so Pillar can be used to transfer sensitive data (in the Salt design, Pillar use of independent encryption s Ession, also to ensure the security of sensitive data). Where can I use the Pillar?

Sensitive information: Each minion can only access the pillar information that Master assigns to itself, such as Ssh-key, encryption certificate
Variables: Differentiated information, etc.,
Any other data that can be used in target and state

Used in targetting, Pillar can be used to select Minion, using the-I option, by default, all data in the master profile is added to Pillar and available to all minion. If you want to disable this default value, you can add the following data to the master profile, restart the service, and the configuration for pillar see/etc/salt/master

Pillar_roots:base:–/srv/pillar
1 Packages.sls2{%ifgrains['OS'] =='RedHat'%# #判断系统时候是redhat, yes, the Apache name is httpd.3 apache:httpd4 Git:git5{%elifgrains['OS'] =='Debian'%}6 Apache:apache27git:git-Core8{% ENDIF%}9 Top.slsTen Base: One             '*': A-Packages -Salt ' * ' Saltutil.refresh_pillar # #after defining the pillar, perform the following command to synchronize
Salt ' * ' pillar.data # # command to view pillar information

Salt-grains&pillar

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.