--- - name: Update und Cronjob Setup für Linux Server (version 4) hosts: int_linux_servers:ext_linux_servers:int_linux_pbs # hosts: linux-testen become: yes vars: script_path: "/home/scripts/default/linux-updater.v4.sh" env_path: "/root/.env/.linux-updater.v4.env" script_src: "./files/linux-updater.v4.sh" env_src: "./files/.linux-updater.v4.env" old_scripts: - "/home/scripts/default/weekly_update.sh" - "/home/scripts/default/weekly-update.v3.sh" - "/home/scripts/default/weekly-update-2.0.sh" - "/home/scripts/default/weekly-update.v2.sh" - "/home/scripts/default/linux-updater.v4.sh" old_env: - "/root/.env/.weekly-update.v3.env" - "/root/.env/.linux-updater.v4.env" - "/root/.env/.linux-update.v4.env" cron_jobs_legacy: - "@weekly bash /home/scripts/default/weekly-update.v3.sh > /dev/null 2>&1" - "@weekly bash /home/scripts/default/weekly-update.v2.sh > /dev/null 2>&1" cron_jobs: - "Monatliches Update Script" - "Woechentliches Weekly-Update Skript v2" - "Wöchentliches Weekly-Update Skript v2" - "Wöchentliches Update Skript" tasks: - name: Lösche alte Skripte ansible.builtin.file: path: "{{ item }}" state: absent with_items: "{{ old_scripts }}" - name: Lösche alte .env ansible.builtin.file: path: "{{ item }}" state: absent with_items: "{{ old_env }}" - name: Entferne alte Cronjobs (legacy) ansible.builtin.cron: name: "Entferne altes Cronjob - {{ item }}" job: "{{ item }}" state: absent with_items: "{{ cron_jobs_legacy }}" - name: Entferne alte Cronjobs (persoenlich) cron: name: "{{ item }}" user: "{{ ansible_user | default('root') }}" state: absent loop: "{{ cron_jobs }}" - name: Entferne alte Cronjobs (cron_file) cron: name: "{{ item }}" user: "{{ ansible_user | default('root') }}" state: absent cron_file: "monthly_script_update" loop: "{{ cron_jobs }}" - name: Stelle sicher, dass das Skriptverzeichnis existiert ansible.builtin.file: path: "/home/scripts/default/" state: directory mode: '0711' - name: Stelle sicher, dass das ENV Verzeichnis existiert ansible.builtin.file: path: "/root/.env/" state: directory mode: '0711' - name: Verteile das neue Skript ansible.builtin.copy: src: "{{ script_src }}" dest: "{{ script_path }}" mode: '0711' - name: Richte neuen Cronjob ein ansible.builtin.cron: name: "Monatliches Update Script" user: "{{ ansible_user | default('root') }}" job: "/home/scripts/default/linux-updater.v4.sh > /dev/null 2>&1" minute: "0" hour: "0" day: "1-7" weekday: "0" month: "*" cron_file: "monthly_script_update" state: "present" - name: Verteile die .env Datei ansible.builtin.copy: src: "{{ env_src }}" dest: "{{ env_path }}" mode: '0711' - name: Führe das Skript einmalig aus ansible.builtin.shell: bash < /home/scripts/default/linux-updater.v4.sh args: executable: /bin/bash