linux-updater/ansible-playbook/update_and_cron_setup.yml
2024-04-13 21:49:44 +02:00

79 lines
2.4 KiB
YAML

---
- name: Update und Cronjob Setup für Linux Server
hosts: int_linux_servers:ext_linux_servers
# hosts: int_dev_linux_servers
become: yes
vars:
script_path: "/home/scripts/default/weekly-update.v3.sh"
env_path: "/root/.env/.weekly-update.v3.env"
script_src: "./files/weekly-update.v3.sh"
env_src: "./files/.weekly-update.v3.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"
- "/root/.env/.weekly-update.v3.env"
old_env:
- "/root/.env/.weekly-update.v3.env"
cron_jobs:
- "@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"
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
ansible.builtin.cron:
name: "Entferne altes Cronjob - {{ item }}"
job: "{{ item }}"
state: absent
with_items: "{{ 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: "Wöchentliches Update Skript"
user: "{{ ansible_user | default('root') }}"
job: "bash {{ script_path }} > /dev/null 2>&1"
special_time: weekly
cron_file: weekly_script_update
- 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/weekly-update.v3.sh
args:
executable: /bin/bash