Parsing log files with timestamp Ansible

66 views
Skip to first unread message

SARANYA devotional R

unread,
Aug 22, 2017, 11:40:13 AM8/22/17
to Ansible Project
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?

Soniya panwar

unread,
Aug 23, 2017, 3:29:19 AM8/23/17
to Ansible Project
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.html"

if anything specific is required please elaborate in details.

SARANYA devotional R

unread,
Aug 24, 2017, 12:50:51 PM8/24/17
to Ansible Project
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.

Soniya panwar

unread,
Aug 25, 2017, 12:25:51 AM8/25/17
to Ansible Project
>> 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.
Reply all
Reply to author
Forward
0 new messages