salt.states.grains

Manage grains on the minion

This state allows for grains to be set. Grains set or altered this way are stored in the 'grains' file on the minions, by default at: /etc/salt/grains

Note: This does NOT override any grains set in the minion file.

salt.states.grains.absent(name, destructive=False, delimiter=':', force=False)

2014.7.0 新版功能.

从grains的配置文件中删除一个grain

name
The grain name
参数:
  • destructive -- If destructive is True, delete the entire grain. If destructive is False, set the grain's value to None. Defaults to False.
  • force --

    If force is True, the existing grain will be overwritten regardless of its existing or provided value type. Defaults to False

    2016.3.0 新版功能.

  • delimiter --

    A delimiter different from the default can be provided.

    2016.3.0 新版功能.

在 2016.3.0 版更改.

This state now support nested grains and complex values. It is also more conservative: if a grain has a value that is a list or a dict, it will not be removed unless the force parameter is True.

grain_name:
  grains.absent: []
salt.states.grains.append(name, value, convert=False, delimiter=':')

2014.7.0 新版功能.

Append a value to a list in the grains config file. The grain that is being appended to (name) must exist before the new value can be added.

name
The grain name
value
The value to append
参数:
  • convert -- If convert is True, convert non-list contents into a list. If convert is False and the grain contains non-list contents, an error is given. Defaults to False.
  • delimiter --

    A delimiter different from the default can be provided.

    2016.3.0 新版功能.

grain_name:
  grains.append:
    - value: to_be_appended
salt.states.grains.list_absent(name, value, delimiter=':')

Delete a value from a grain formed as a list.

2014.1.0 新版功能.

name
The grain name.
value
The value to delete from the grain list.
参数:delimiter --

A delimiter different from the default : can be provided.

2016.3.0 新版功能.

The grain should be list type

roles:
  grains.list_absent:
    - value: db

For multiple grains, the syntax looks like:

roles:
  grains.list_absent:
    - value:
      - web
      - dev
salt.states.grains.list_present(name, value, delimiter=':')

2014.1.0 新版功能.

Ensure the value is present in the list-type grain. Note: If the grain that is provided in name is not present on the system, this new grain will be created with the corresponding provided value.

name
The grain name.
value
The value is present in the list type grain.
参数:delimiter --

A delimiter different from the default : can be provided.

2016.3.0 新版功能.

The grain should be list type

roles:
  grains.list_present:
    - value: web

For multiple grains, the syntax looks like:

roles:
  grains.list_present:
    - value:
      - web
      - dev
salt.states.grains.present(name, value, delimiter=':', force=False)

Ensure that a grain is set

在 2016.3.0 版更改.

name
The grain name
value
The value to set on the grain
参数:
  • force --

    If force is True, the existing grain will be overwritten regardless of its existing or provided value type. Defaults to False

    2016.3.0 新版功能.

  • delimiter --

    A delimiter different from the default can be provided.

    2016.3.0 新版功能.

It is now capable to set a grain to a complex value (ie. lists and dicts) and supports nested grains as well.

If the grain does not yet exist, a new grain is set to the given value. For a nested grain, the necessary keys are created if they don't exist. If a given key is an existing value, it will be converted, but an existing value different from the given key will fail the state.

If the grain with the given name exists, its value is updated to the new value unless its existing or provided value is complex (list or dict). Use force: True to overwrite.

cheese:
  grains.present:
    - value: edam

nested_grain_with_complex_value:
  grains.present:
    - name: icinga:Apache SSL
    - value:
      - command: check_https
      - params:  -H localhost -p 443 -S

with,a,custom,delimiter:
  grains.present:
    - value:     yay
    - delimiter: ,