# Grains

### Wie sieht es unter der Oberfläche aus?

> Salt comes with an interface to derive information about the underlying system. This is called the grains interface, because it presents salt with grains of information. Grains are collected for the operating system, domain name, IP address, kernel, OS type, memory, and many other system properties.

```bash
salt '*' grains.items
salt '*' grains.fetch roles
salt '*' grains.fetch ipv4
salt '*' grains.fetch osfinger
```

### Adressieren Sie Minions über Grains

#### Windows oder Linux?

```bash
salt -G 'kernel:linux' test.ping
salt -G 'Os:Windows' test.ping
salt -G 'osfinger:Ubuntu-18.04' test.ping
```

#### Subnetze ansprechen

```bash
salt -G 'ip_interfaces:eth0:10.8.178.23' test.ping
salt -G 'ipv4:10.8.178.*' test.ping
```

#### Mehrere Grains zum Filtern verwenden

```
salt -C 'G@ipv4:10.8.178.* or G@ipv4:192.168.*' test.ping
salt -C 'G@ipv4:172.* and ( G@kernel:windows or G@kernel:linux )' test.ping
```

{% hint style="info" %}
Achten Sie bei Klammern auf ein Leerzeichen nach der Klammer.
{% endhint %}

📖 <https://docs.saltproject.io/en/latest/topics/targeting/compound.html>

### Eigene Grains setzen

{% code title="/etc/salt/minion.d/grains.conf" %}

```yaml
grains:
  customer: kramm
  city: berlin
  contact:
    - phone: 030 09876
    - street: bla
```

{% endcode %}

Grains kann man auch vom Master den Minions "zuweisen":

```bash
salt '<SOME_MINION>' grains.set role web
salt '<SOME_MINION>' grains.set roles [web,database]
salt 'delia' grains.set 'apps:myApp' '{port: 2209}'
salt delia grains.set test \
  "{'location': {'city':'Essen', 'country':'Germany'}, 'newkey':'value'}" \
  force=True
```

{% hint style="warning" %}
Beachten Sie, dass mit Sie mit `grains.set` vorhandene Grains ggf. überschreiben. Sie können auch `grains.append` verwenden.
{% endhint %}

Grains, welche Sie mit dem zuvor genannten Befehl setzen, werden vom Minion in die Datei `/etc/salt/grains` gespeichert. Sollte eine weitere Grains-Konfigurationsdatei in `/etc/salt/minion.d/` existieren, hat diese Vorrang und die per `grains.set` oder `grains.append` gesetzten Grains werden ignoriert.

📖 Mehr Informationen in der [Projektdokumentation](https://docs.saltproject.io/en/latest/ref/modules/all/salt.modules.grains.html).&#x20;


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://thorstenkramm.gitbook.io/saltstack/minions-adressieren/grains.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
