updates-dashboard-ansible/playbooks/auto-updates-result.yml
2022-08-18 10:18:28 +02:00

56 lines
1.7 KiB
YAML

---
# This is to get the auto-updates script status from log file
# It returns in stat_log:
# - OUT if file older than 40 days
# - ERR if recent but ERROR in file
# - OK if recent and OK in file
# nothing else (main playbook manage it as an UNK status)
- name: check if there is an auto-updates log file
stat: path="{{ log_dir }}/scripts/auto-updates.log"
register: stat_log
- name: set error status
set_fact: auto_updates_status=ERR
when: not stat_log.stat.exists
- name: check if log file is less than 1 month old
shell: "find {{ log_dir }}/scripts/ -name 'auto-updates.log' -mtime -40 | wc -l"
register: date_log
when: stat_log.stat.exists
- name: set outdated status
set_fact: auto_updates_status=OUT
when: date_log.stdout is defined and date_log.stdout != "1"
- name: check ok status if recent log file
command: "grep OK {{ log_dir }}/scripts/auto-updates.log"
register: ok_log
failed_when: False
when: date_log.stdout is defined and date_log.stdout == "1"
- name: set ok status
set_fact: auto_updates_status=OK
when: ok_log.rc is defined and ok_log.rc != 1
- name: check error if old log file
command: "grep ERROR {{ log_dir }}/scripts/auto-updates.log"
register: error_log
failed_when: false
when: date_log.stdout is defined and date_log.stdout == "1"
- name: set error status
set_fact: auto_updates_status=ERR
when: error_log.rc is defined and error_log.rc != 1
- name: check running status if recent log file
command: "grep RUNNING {{ log_dir }}/scripts/auto-updates.log"
register: running_log
failed_when: false
when: stat_log.stat.exists
- name: set error status
set_fact: auto_updates_status=ERR
when: running_log.rc is defined and running_log.rc != 1