diff --git a/eval.sh b/eval.sh new file mode 100644 index 0000000..a0c1796 --- /dev/null +++ b/eval.sh @@ -0,0 +1,39 @@ +#! /bin/bash +set -e +set -u + +source /root/functions.sh + +file=/home/epsi/bin/mysql_backup.sh + +addHeader + +dirMustExist /home/epsi/bin +fileMustExist /home/epsi/bin/mysql_backup.sh +fileMustContain $file 'set -u' +fileMustContain $file if +fileMustContain $file mysqldump +fileMustContain $file exit +fileMustContain $file '$#' +fileMustContain $file '$1' +fileMustContain $file '$?' +fileMustContain $file 'date' +dirMustExist /srv/backups/mysql/2020-11-13 +n=$(test -f $file && wc -l $file &> /dev/null) ; echo -ne "${n}\t" +fileMustContain /etc/crontab $file + +file=/home/epsi/bin/file_backup.sh +dirMustExist /home/epsi/bin +fileMustExist $file +fileMustExist /etc/backup.include +fileMustContain $file 'set -u' +fileMustContain $file if +fileMustContain $file tar +fileMustContain $file exit +fileMustContain $file '$#' +fileMustContain $file '$1' +fileMustContain $file '$?' +fileMustContain $file 'date' +dirMustExist /srv/backups/files/2020-11-13 +n=$(test -f $file && wc -l $file &> /dev/null) ; echo -ne "${n}\t" +fileMustContain /etc/crontab $file diff --git a/eval.yml b/eval.yml new file mode 100644 index 0000000..3f04179 --- /dev/null +++ b/eval.yml @@ -0,0 +1,43 @@ +--- +- hosts: + - all + user: epsi + become: true + gather_facts: false + vars: + result_file: "{{ '%Y-%m-%d' | strftime }}_tp.csv" + script: eval.sh + + pre_tasks: + - name: insert header + lineinfile: + path: "{{ result_file }}" + line: "machine\tuser\tdir bin\tscript exists\tif\tmysqldump\texit\targ0\targ1\targ2\trc\tdate\texecOk\ttaille" + state: present + create: true + delegate_to: localhost + + tasks: + - name: copy script + copy: + src: "{{ item }}" + dest: /root + mode: 0700 + loop: + - "{{ script }}" + + - name: get latest version of functions.sh + git: + repo: ssh://infra.opendoor.fr:2222/srv/git/repos/tom/eval_functions.git + dest: root/eval_functions.git + + - name: exec script + command: /root/eval.sh + register: result + + - name: get result + lineinfile: + path: "{{ result_file }}" + line: "{{ result.stdout }}" + create: true + delegate_to: localhost \ No newline at end of file