Saltstack grains

From wikinotes

Grains are facts about a system that a minion is running on. You can target machines based on this information, or alter states/configuration based on it.

Intro

commandline

salt-call grains.ls                    # list all grains on a server
salt-call grains.get master            # get value of 'master' grain
salt-call grains.get --out txt master  # alter output of grains

statefiles

{% if salt.__grains__["master"] == "x.x.x.x" %}  # access in salt states

Custom Grains

You can define your own grains, accessible alongside the others.

# /usr/local/etc/salt/minion
master: x.x.x.x
grains:
  aws: 1
  gcp: 0

Builtin Grains

Some useful grains

os_family

Arch     # archlinux
Debian   # debian, ubuntu, ...
FreeBSD  # freebsd
Windows  # windows
# ? macos