# Action when process stops appending to a file

**URL:** <https://forum.ansible.com/t/action-when-process-stops-appending-to-a-file/19820>\
**Category:** Ansible Project\
**Created:** [November 20, 2015, 7:01pm UTC](https://forum.ansible.com/t/action-when-process-stops-appending-to-a-file/19820 "2015-11-20T19:01:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tom\_rkba](https://avatars.discourse-cdn.com/v4/letter/t/e79b87/32.png) [@tom\_rkba](https://forum.ansible.com/u/tom_rkba)\
**Post date:** [November 20, 2015, 7:01pm UTC](https://forum.ansible.com/t/action-when-process-stops-appending-to-a-file/19820/1 "2015-11-20T19:01:53Z")

</div>

How do I get Ansible to monitor a log file and take an action when the process stops appending?

I have a high volume process that we’ll drain before stopping it. The process will have queued a significant number of transactions just prior being placed in administrative mode. The process will continue to handle those items while appending to the log. I want Ansible to look at the file, verify that nothing is being added to it, and then stop the service.

How do I express this in a playbook?

---

<div class="post-metadata">

**Author:** ![Markus\_Ellers](https://avatars.discourse-cdn.com/v4/letter/m/35a633/32.png) [@Markus\_Ellers](https://forum.ansible.com/u/Markus_Ellers)\
**Post date:** [November 21, 2015, 9:32pm UTC](https://forum.ansible.com/t/action-when-process-stops-appending-to-a-file/19820/2 "2015-11-21T21:32:46Z")

</div>

I have played arouind a bit and came up with this. Maybe it will help:

- hosts: localhost  
sudo: true  
tasks:

- name: Create file  
file: path=/testfile state=touch

- name: Get mtime  
stat: path=/testfile  
register: testfile

- name: wait till there have been no changes to the file for 10 seconds  
debug: msg=“Not yet”  
register: result  
until: “{{lookup(‘pipe’, ‘date +%s’)}}-testfile.stat.mtime \>=10”  
delay: 3  
retries: 10  
ignore\_errors: true

- debug: var=result

---

<div class="post-metadata">

**Author:** ![tom\_rkba](https://avatars.discourse-cdn.com/v4/letter/t/e79b87/32.png) [@tom\_rkba](https://forum.ansible.com/u/tom_rkba)\
**Post date:** [November 23, 2015, 3:13pm UTC](https://forum.ansible.com/t/action-when-process-stops-appending-to-a-file/19820/3 "2015-11-23T15:13:54Z")

</div>

I tried this, but Ansible exits while my test shell script is appending lines to the file.

until: “{{lookup(‘pipe’, ‘date +%s’)}}-testfile.stat.mtime \>=10”

Is there some good documentation on ‘until’?

```auto
until: result.stdout.find("all systems go") != -1

```

Where can I find the various methods (such as stdout.find) that are available for Ansible? Is there a good list somewhere? I’ve been looking around and not finding much.

---

<div class="post-metadata">

**Author:** ![Markus\_Ellers](https://avatars.discourse-cdn.com/v4/letter/m/35a633/32.png) [@Markus\_Ellers](https://forum.ansible.com/u/Markus_Ellers)\
**Post date:** [November 23, 2015, 7:37pm UTC](https://forum.ansible.com/t/action-when-process-stops-appending-to-a-file/19820/4 "2015-11-23T19:37:42Z")

</div>

For do until:

[https://docs.ansible.com/ansible/playbooks\_loops.html#do-until-loops](https://docs.ansible.com/ansible/playbooks_loops.html#do-until-loops)

The output of the stat module is documented in the documentation page of the module. But you can look at what is available in general by registering the output of a task and then putting debug: var=variablename as the next task.

I haven’t put any error handling in my example playbook so you would probably have to add another task in case the loop times out. The values I chose were OK for testing but you will need to find proper timings for your use case.  
additionally you can read up on lookups here: [https://docs.ansible.com/ansible/playbooks\_lookups.html](https://docs.ansible.com/ansible/playbooks_lookups.html)

I chose to not use to look into the stdout of another task because you specifically asked to look if anything still appends to a file. If you have a log entry that tells you when your processes are finished I would recommend using that as an inidcator instead og the mtime.
