From a513dd5d384212430edceff4e5815cb5d775cf31 Mon Sep 17 00:00:00 2001 From: donotos <37663674+donotos@users.noreply.github.com> Date: Fri, 13 Jan 2023 19:43:23 +0100 Subject: [PATCH] add test scripts for crontab --- linux_edit_crontab.yml | 27 +++++++++++++++++++++++++++ linux_edit_crontab_bad.yml | 21 +++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 linux_edit_crontab.yml create mode 100644 linux_edit_crontab_bad.yml diff --git a/linux_edit_crontab.yml b/linux_edit_crontab.yml new file mode 100644 index 0000000..93cf838 --- /dev/null +++ b/linux_edit_crontab.yml @@ -0,0 +1,27 @@ +--- +- name: Edit Cron jobs. + hosts: all + + tasks: + - name: On modifie le Crontab + ansible.builtin.cron: + day: "{{ lookup('env', 'VMWARE_HOST') }}" + username: "{{ lookup('env', 'VMWARE_USER') }}" + password: "{{ lookup('env', 'VMWARE_PASSWORD') }}" + datacenter: "{{ esxi_host }}" + uuid: "{{ vm_uuid }}" + state: "{{ snap_state }}" + snapshot_name: "{{ snap_name }}" + description: "{{ snap_descr }}" + register: mkcron + +- name: move backup file + copy: + remote_src: yes + src: "{{ mkcron.backup_file }}" + dest: /tmp/cron_backup + +- name: remove original file + file: + path: "{{ mkcron.backup_file }}" + state: absent diff --git a/linux_edit_crontab_bad.yml b/linux_edit_crontab_bad.yml new file mode 100644 index 0000000..8184af9 --- /dev/null +++ b/linux_edit_crontab_bad.yml @@ -0,0 +1,21 @@ +--- +- name: Update Crontab + hosts: all + + tasks: + - name: On execute la commande "sudo crontab -u root -l > crontab_new" + shell: + cmd: sudo crontab -u root -l > crontab_new + + - name: On execute la commande "sed de remplacement" + shell: + cmd: sudo sed -i -e "s/backup.sh/backup.sh -b/g" crontab_new + + - name: On execute la commande "sudo crontab -u root crontab_new" + shell: + cmd: sudo crontab -u root crontab_new + + - name: remove crontab_new + file: + path: crontab_new + state: absent