Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Empfohlene Antworten

Veröffentlicht

Hey,

ich stehe vor folgendem Problem:
Ich möchte mit Ansible Backups in Ordnern speichern. Diese Ordner bekommen das aktuelle Datum als Namen.
Diese möchte ich dann später löschen, wenn Sie älter als X Tage sind.

Sprich immer wenn ich das Playbook ausführe, sollen alle Ordner an diesem Pfad gelöscht werden, die älter als Tag X sind.
Hat jemand eine Idee, wie ich das hinbekomme?

Erstellt werden die Ordner nach folgendem Muster: (Erstmal nur das erzeugen der Datei, mit dem kopieren klappt es ja aber nach dem gleichen Prinzip später)

---
- hosts: server_debian
  become: yes
  tasks:
    - name: Ordner mit Datumsname anlegen
      file:
        path: /etc/Datum/{{ ansible_date_time.date }}
        state: directory
        force: no
        
    - name: backup-file mit Uhrzeit anlegen
      file:
        path: /etc/Datum/{{ ansible_date_time.date }}/{{ ansible_date_time.time }}
        state: touch


Ich hatte mir erstmal die Lösung zurecht gebastelt, aber die löscht dann nur alle Ordner die wirklich 14 Tage alt sind und nicht älter:
 

---
- hosts: server_debian
  become: yes
  tasks:
    - set
  
    - name: Datum
      file:
        path: /etc/Datum/{{ '%Y-%m-%d' | strftime( ( ansible_date_time['epoch'] | int ) - ( 86400 * 14 )  ) }}
        state: absent

 

Versuchs mal mit dem Modul "find" + dem Parameter "age".

Siehe hier: https://docs.ansible.com/ansible/2.3/find_module.html
-> "Select files whose age is equal to or greater than the specified time"

Und eine praktische Anwendung hier: https://stackoverflow.com/questions/45855743/double-conditional-delete-all-folders-older-than-3-days-but-keep-a-minimum-of/45857847
(etwas anderer Fall, aber von der Syntax her vergleichbar)

Sollte dann in etwa sowas hier sein:

---
- hosts: all
  tasks:
    - name: find all files that are older than three days
      find:
        paths: "/path/to/folder/"
        age: "3d"
        file_type: directory
      register: dirsOlderThan3d
    - name: remove older than 3 days
      file:
        path: "{{ item.path }}" 
        state: absent
      with_items: "{{ (dirsOlderThan3d.files }}

(schnelles c+p ;) keine Garantie für Funktionalität)

Erstelle ein Konto oder melde dich an, um einen Kommentar zu schreiben.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.