Setting grains dynamically
As you already know, grains hold variables that describe certain aspects of a Minion. This could be information about the operating system, the hardware, the network, and so on. It can also contain statically defined user data, which is configured either in /etc/salt/minion
or /etc/salt/grains
. It is also possible to define grains dynamically using grains modules.
Setting some basic grains
Grains modules are interesting in that so long as the module is loaded, all public functions will be executed. As each function is executed, it will return a dictionary, which contains items to be merged into the Minion's grains.
Let's go ahead and set up a new grains module to demonstrate. We'll prepend the names of the return data with a z
so that it is easy to find.
''' Test module for Extending SaltStack This module should be saved as salt/grains/testdata.py ''' def testdata(): ''' Return some test data ''' return {'ztest1': True}
Go ahead and save this file...