# Parsing log files with timestamp Ansible

**URL:** <https://forum.ansible.com/t/parsing-log-files-with-timestamp-ansible/25308>\
**Category:** Ansible Project\
**Created:** [August 22, 2017, 3:40pm UTC](https://forum.ansible.com/t/parsing-log-files-with-timestamp-ansible/25308 "2017-08-22T15:40:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![SARANYA\_devotional\_R](https://avatars.discourse-cdn.com/v4/letter/s/43a26b/32.png) [@SARANYA\_devotional\_R](https://forum.ansible.com/u/SARANYA_devotional_R)\
**Post date:** [August 22, 2017, 3:40pm UTC](https://forum.ansible.com/t/parsing-log-files-with-timestamp-ansible/25308/1 "2017-08-22T15:40:12Z")

</div>

I would like to search/wait for a string in a recently created file(test\_build\_201708211712.log) which has timestamp.

-rw-rw-r-- 1 test test 579 Aug 21 16:00 test\_build\_201708211559.log  
-rw-rw-r-- 1 test test 579 Aug 21 17:12 test\_build\_201708211712.log

How can I achieve this in Ansible?

---

<div class="post-metadata">

**Author:** ![Soniya\_panwar](https://avatars.discourse-cdn.com/v4/letter/s/22d042/32.png) [@Soniya\_panwar](https://forum.ansible.com/u/Soniya_panwar)\
**Post date:** [August 23, 2017, 7:29am UTC](https://forum.ansible.com/t/parsing-log-files-with-timestamp-ansible/25308/2 "2017-08-23T07:29:19Z")

</div>

you can use lineinfile module for this.

for more understanding on lineinfile module you can go through to the link “[http://docs.ansible.com/ansible/latest/lineinfile\_module.htm](http://docs.ansible.com/ansible/latest/lineinfile_module.htm)l”

if anything specific is required please elaborate in details.

---

<div class="post-metadata">

**Author:** ![SARANYA\_devotional\_R](https://avatars.discourse-cdn.com/v4/letter/s/43a26b/32.png) [@SARANYA\_devotional\_R](https://forum.ansible.com/u/SARANYA_devotional_R)\
**Post date:** [August 24, 2017, 4:50pm UTC](https://forum.ansible.com/t/parsing-log-files-with-timestamp-ansible/25308/3 "2017-08-24T16:50:50Z")

</div>

I want to find the recently created file under a folder and cat to the file for the contents updates which can be visible while running a play in output.

---

<div class="post-metadata">

**Author:** ![Soniya\_panwar](https://avatars.discourse-cdn.com/v4/letter/s/22d042/32.png) [@Soniya\_panwar](https://forum.ansible.com/u/Soniya_panwar)\
**Post date:** [August 25, 2017, 4:25am UTC](https://forum.ansible.com/t/parsing-log-files-with-timestamp-ansible/25308/4 "2017-08-25T04:25:51Z")

</div>

> > I want to find the recently created file under a folder and cat to the file for the contents updates which can be visible while running a play in output.

use this play in your playbook you will get expected result:

> - name: safely use  
> shell: find /var/log/ -maxdepth 1 -type f -printf ‘%TY-%Tm-%Td %TT %p\n’| sort -r | head -1 | awk ‘{print $3}’ | xargs cat  
> register: myoutput
> - debug: var=myoutput.stdout\_lines

here \</var/log/\> → give your folder path from where you want to cat the file for the contents.
