Dateien editieren

Der Salt-Master übernimmt die Kontrolle über Dateien auf den Minion

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

Beispiel Message of the day

/srv/salt/init/motd.sls
#
# 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

Trockenübung

/srv/salt/file-examples.sls
#
# 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

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.

Last updated