https://stackoverflow.com/questions/53385430/monitor-recent-entries-of-a-log-file-with-ansible
-
name: HUP certain_process
command: "pkill -HUP certain_process" -
name: Get the content of the last line in logfile
shell: tail -1 logfile
register: tail_output -
name: Waits until process HUP finishes
wait_for:
path: '{{tail_output.stdout_lines}}'
search_regex: "Configuration data reloaded"
delay: 20
timeout: 280
register: wait
ignore_errors: True -
name: Fail if HUP failed
fail: msg="App HUP failed"
when: wait|failed
and the output:
TASK [HUP certain_process] **************************************************************
Tuesday 20 November 2018 01:14:18 +0000 (0:00:05.575) 0:00:20.148 ******
changed: [host1]
TASK [Get the contents of the last line in logfile] ***************
Tuesday 20 November 2018 01:14:23 +0000 (0:00:05.413) 0:00:25.561 ******
changed: [host1]
TASK [Waits until process HUP finishes] ****************************************
Tuesday 20 November 2018 01:14:27 +0000 (0:00:04.067) 0:00:29.629 ******
fatal: [host1]: FAILED! => {"changed": false, "elapsed": 280, "failed": true, "msg": "Timeout when waiting for search string Configuration data reloaded in ['Nov 20 01:44:28 host1 SYS(15) HUP signal detected: reloading configuration data...']"}
...ignoring
TASK [Fail if hupped failed] ***************************************************
Tuesday 20 November 2018 01:19:13 +0000 (0:04:45.737) 0:05:15.366 ******
fatal: [host1]: FAILED! => {"changed": false, "failed": true, "msg": "App HUP failed"}
to retry, use: --limit @/export/home/carlos/project/policyUpdate.retry
网友评论