天天看點

salt grains - store static data in grains

[size=large]saltstack 學習之grains[/size]

【基本介紹】

Salt comes with an interface to derive information about the underlying system. This is called the grains interface, because it presents salt with grains of information.It is important to remember that grains are bits of information loaded when the salt minion starts, so this information is static. This means that the information in grains is unchanging, therefore the nature of the data is static. So grains information are things like the running kernel, or the operating system.(grains是跟系統有關的存儲一下不變的變量,例如kernel,作業系統等參數)

我對pillar,grains的差別了解

pillar - 存儲會變動的變量

grains - 存儲不變的變量

【配置】

檔案:/etc/salt/minion

配置grains的變量以及重新整理,緩存等

【原則】

grains是可以覆寫的,原則是4到1依次覆寫

Core grains can be overridden by custom grains. As there are several ways of defining custom grains, there is an order of precedence which should be kept in mind when defining them. The order of evaluation is as follows:

1. Core grains.

2. Custom grains in /etc/salt/grains.

3. Custom grains in /etc/salt/minion.

4. Custom grain modules in _grains directory, synced to minions.

Each successive evaluation overrides the previous ones, so any grains defined in /etc/salt/grains that have the same name as a core grain will override that core grain. Similarly, /etc/salt/minion overrides both core grains and grains set in /etc/salt/grains, and custom grain modules will override any grains of the same name.

【使用】

salt '*' grains.items - 獲得所有的grains

salt -G 'os:CentOS' test.ping - ping所有os是CentOS的

【參考】

[url]http://docs.saltstack.com/en/latest/topics/targeting/grains.html[/url]

繼續閱讀