There is a service that performs an update of our system, the execution status can only be viewed in the log or in the service status. The problem is that the execution process takes time, and it will not be possible to just read a static log. How to use Ansible to read a dynamic log before the "Update success" line appears
Asked
Active
Viewed 546 times
1 Answers
0
Regarding
How to use Ansible to read a dynamic log before the "Update success" line appears?
the following approach of Retrying a task until a condition is met and Return Values might work for you.
---
- hosts: test
become: false
gather_facts: false
tasks:
- name: Check for success
shell:
cmd: grep 'Update success' /home/{{ ansible_user }}/service.log
register: result
retries: 5
delay: 5
until: result.rc == 0
Since grep
has a return code of 0
if it find the pattern and a return code of 1
if not, resulting into an output of
PLAY [test] ******************************************
FAILED - RETRYING: Check for success (5 retries left).
FAILED - RETRYING: Check for success (4 retries left).
FAILED - RETRYING: Check for success (3 retries left).
TASK [Check for success] *****************************
changed: [test.example.com]
after writing echo "Update success" >> service.log
on the test host.
Further Q&A

U880D
- 8,601
- 6
- 24
- 40