Grains
Grains are minion data calculated when minion starts. It contains static data like OS version, CPU cores, etc. This data is generated in minion and presented to master.
List the default grains configured on a minion.
- salt vagrant-centos65.vagrantup.com grains.ls # This just lists the keys
- salt vagrant-centos65.vagrantup.com grains.items # This lists all the keys & values
- salt vagrant-centos65.vagrantup.com grains.item os --out=txt # single value
Setting Grains
- salt centos65-minion grains.setval myenv stage
- salt ubuntu-14.04-amd64-vbox grains.setval myenv dev
- salt vagrant-centos65.vagrantup.com grains.setval roles '[webserver,appserver]'
- salt centos65-minion grains.setval roles '[webserver,appserver,database]'
- salt ubuntu-14.04-amd64-vbox grains.setval roles '[webserver,appserver,database]'
- salt \* grains.item myenv roles # query all of these roles
Pillars
Pillars are data from the Master. Pillar data is stored on the master. But the data is available only for the given minion.
Querying pillar data
- salt \* pillar.items
Configuring pillar root in masters configuration
--------------------------------------------
# cat /etc/salt/master.d/pillar.conf
# cat /etc/salt/master.d/pillar.conf
pillar_roots:
base:
- /srv/salt/pillar/base
--------------------------------------------- service salt-master restart
Pillar Top file
--------------------------------------------
# cat /srv/salt/pillar/base/top.sls
base:
'*':
- default
# cat /srv/salt/pillar/base/top.sls
base:
'*':
- default
--------------------------------------------
--------------------------------------------
--------------------------------------------
# cat /srv/salt/pillar/base/default.sls
my_data: some data for stuff
--------------------------------------------
my_data: some data for stuff
--------------------------------------------
Pillar data for user management
--------------------------------------------
# cat /srv/salt/pillar/base/users/all.sls
users:
wilma: 2001
fred: 2002
barney: 2003
betty: 2004
# cat /srv/salt/pillar/base/users/all.sls
users:
wilma: 2001
fred: 2002
barney: 2003
betty: 2004
--------------------------------------------
--------------------------------------------
--------------------------------------------
# cat /srv/salt/pillar/base/users/stage.sls
users:
wilma: 2001
barney: 2003
betty: 2004
users:
wilma: 2001
barney: 2003
betty: 2004
--------------------------------------------
--------------------------------------------
--------------------------------------------
# cat /srv/salt/pillar/base/users/dba.sls
users:
wilma: 2001
--------------------------------------------
users:
wilma: 2001
--------------------------------------------
Re-touch Top file
--------------------------------------------
# cat /srv/salt/pillar/base/top.sls
base:
'*':
- default
'G@myenv:prod and G@roles:database':
- match: compound
- users.dba
'myenv:stage':
- match: grain
- users.stage
'myenv:dev':
- match: grain
- users.all
--------------------------------------------
# cat /srv/salt/pillar/base/top.sls
base:
'*':
- default
'G@myenv:prod and G@roles:database':
- match: compound
- users.dba
'myenv:stage':
- match: grain
- users.stage
'myenv:dev':
- match: grain
- users.all
--------------------------------------------
Validate the top file
[root@vagrant-centos65 base]# salt \* pillar.item users