> For the complete documentation index, see [llms.txt](https://thorstenkramm.gitbook.io/saltstack/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://thorstenkramm.gitbook.io/saltstack/salt-states/dateien-editieren.md).

# Dateien editieren

Zahlreiche State-Module ermöglichen das Kopieren, Ändern, Anlegen und Löschen von Dateien auf den Minion.

### Beispiel Message of the day

{% code title="/srv/salt/init/motd.sls" %}

```yaml
#
# Disable Ubuntu Ads
#
/etc/update-motd.d/80-livepatch:
  file.managed:
    - mode: 0644

/etc/update-motd.d/50-motd-news:
  file.managed:
    - mode: 0644

#
# Add a new section to the motd
#
/etc/update-motd.d/96-salt:
  file.managed:
    - contents: |
        #!/bin/sh
        echo "##########################################"
        echo ""
        echo " This system is managed by Salt"
        echo " Files might be overwritten at any time"
        echo ""
        echo "##########################################"
    - mode: 0755
```

{% endcode %}

{% hint style="info" %}
Achten Sie auf die sechsfache Einrückung des Text-Blockes. Bei einer nur sechsfachen Einrückung würden die Kommentarzeichen als Yaml-Kommentare gewertet, was zu einem Syntaxfehler führt.
{% endhint %}

![6-fache Einrückung, um Blöcke als Nicht-Yaml zu kennzeichnen ](/files/-LbIKWhz0TnRPFI9XkLt)

### Trockenübung

{% code title="/srv/salt/file-examples.sls" %}

```yaml
#
# Just create and change a file
#
create:
  file.managed:
    - name: /tmp/file1.txt
    - contents: This file is managed by salt

append:
  file.append:
    - name: /tmp/file1.txt
    - text: This is the second line of the file

insert:
  file.line:
    - name: /tmp/file1.txt
    - content: >- 
        This is line: #0 
        It's just a single line with special characters
    - mode: ensure
    - before: ^This file is managed by salt
    
copy:
  file.managed:
    - name: /tmp/file-examples.txt
    - source: salt://file-examples.sls
    - mode: 0644
```

{% endcode %}

{% hint style="success" %}
Beachten Sie die Syntax `content: >-` Was Sie in Yaml über mehrere Zeilen eingeben, wird am Ziel in eine Zeile ohne Umbruch geschrieben. Achten Sie auf die sechsfache Einrückung.
{% endhint %}

{% hint style="info" %}
Dateien, die Sie vom Master auf die Minions kopieren möchten, müssen sich innerhalb von `file_roots` i.d.R. `/srv/salt` befinden und werden relativ zu diesem Ordner angegeben.&#x20;
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://thorstenkramm.gitbook.io/saltstack/salt-states/dateien-editieren.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
