Saltstack grains: Difference between revisions
From wikinotes
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
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. | 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. | ||
= os_family = | = Intro = | ||
<blockquote> | |||
commandline | |||
<syntaxhighlight lang="bash"> | |||
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 | |||
</syntaxhighlight> | |||
statefiles | |||
<syntaxhighlight lang="yaml"> | |||
{% if salt.__grains__["master"] == "x.x.x.x" %} # access in salt states | |||
</syntaxhighlight> | |||
</blockquote><!-- Intro --> | |||
= Custom Grains = | |||
<blockquote> | |||
You can define your own grains, accessible alongside the others. | |||
<syntaxhighlight lang="yaml"> | |||
# /usr/local/etc/salt/minion | |||
master: x.x.x.x | |||
grains: | |||
aws: 1 | |||
gcp: 0 | |||
</syntaxhighlight> | |||
</blockquote><!-- Custom Grains --> | |||
= Builtin Grains = | |||
<blockquote> | |||
Some useful grains | |||
== os_family == | |||
<blockquote> | <blockquote> | ||
<source lang="bash"> | <source lang="bash"> | ||
Line 11: | Line 42: | ||
</source> | </source> | ||
</blockquote><!-- os_family --> | </blockquote><!-- os_family --> | ||
</blockquote><!-- Grains --> |
Latest revision as of 01:58, 15 August 2022
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 grainsstatefiles
{% 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