# ansible tail file

**URL:** <https://forum.ansible.com/t/ansible-tail-file/29997>\
**Category:** Ansible Project\
**Created:** [March 27, 2019, 2:22pm UTC](https://forum.ansible.com/t/ansible-tail-file/29997 "2019-03-27T14:22:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jer8jer](https://avatars.discourse-cdn.com/v4/letter/j/7ab992/32.png) [@jer8jer](https://forum.ansible.com/u/jer8jer)\
**Post date:** [March 27, 2019, 2:22pm UTC](https://forum.ansible.com/t/ansible-tail-file/29997/1 "2019-03-27T14:22:53Z")

</div>

I want to start the nodes serially so I need to wait until I see “Confluence is ready to serve”. The search\_regex looks at the entire file so I added part of the date. This only works when the application has not been restarted within the hour. Is there a better way to search a tail of a file?

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [March 27, 2019, 2:35pm UTC](https://forum.ansible.com/t/ansible-tail-file/29997/2 "2019-03-27T14:35:47Z")

</div>

Rename the log before you start, then you have a clean log file.

---

<div class="post-metadata">

**Author:** ![jer8jer](https://avatars.discourse-cdn.com/v4/letter/j/7ab992/32.png) [@jer8jer](https://forum.ansible.com/u/jer8jer)\
**Post date:** [March 27, 2019, 5:22pm UTC](https://forum.ansible.com/t/ansible-tail-file/29997/3 "2019-03-27T17:22:11Z")

</div>

I found a solution on stacktrace:

```auto
vars:
  log_file_to_check: <path_to_log_file>
  wanted_pattern: <pattern_to_match>

tasks:
  - name: Get the contents of the last line in {{ log_file_to_check }}
    shell: tail -n 1 {{ log_file_to_check }}
    register: tail_output

  - name: Create a variable with a meaningful name, just for clarity
    set_fact:
      last_line_of_the_log_file: "{{ tail_output.stdout }}"

  ### do some other tasks ###

  - name: Match "{{ wanted_pattern }}" appearing after "{{ last_line_of_the_log_file }}" in {{ log_file_to_check }}
    wait_for:
      path: "{{ log_file_to_check }}"
      search_regex: "{{ last_line_of_the_log_file }}\r(.*\r)*.*{{ wanted_pattern }}"

```

but the last line confuses me. the \r(._\r)_.\* in particular

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [March 27, 2019, 5:23pm UTC](https://forum.ansible.com/t/ansible-tail-file/29997/4 "2019-03-27T17:23:34Z")

</div>

I used an alternative approach, when I still maintained our Confluence instance.  
My playbook was watching the socket where the JVM was listening on:

- name: create systemd startup script  
&nbsp;&nbsp;template:  
&nbsp;&nbsp;&nbsp;&nbsp;src: startup-systemd.j2  
&nbsp;&nbsp;&nbsp;&nbsp;dest: /etc/systemd/system/confluence.service  
&nbsp;&nbsp;register: service

- name: Reload service definition  
&nbsp;&nbsp;shell: 'systemctl daemon-reload'  
&nbsp;&nbsp;when: service.changed

- name: Ensure service is enabled  
&nbsp;&nbsp;service:  
&nbsp;&nbsp;&nbsp;&nbsp;name: confluence  
&nbsp;&nbsp;&nbsp;&nbsp;enabled: yes  
&nbsp;&nbsp;&nbsp;&nbsp;state: started

- name: Wait for JVM to come up  
&nbsp;&nbsp;wait\_for:  
&nbsp;&nbsp;&nbsp;&nbsp;host: localhost  
&nbsp;&nbsp;&nbsp;&nbsp;port: 8090  
&nbsp;&nbsp;&nbsp;&nbsp;delay: 2  
&nbsp;&nbsp;&nbsp;&nbsp;timeout: 120  
&nbsp;&nbsp;&nbsp;&nbsp;state: started

---

<div class="post-metadata">

**Author:** ![jer8jer](https://avatars.discourse-cdn.com/v4/letter/j/7ab992/32.png) [@jer8jer](https://forum.ansible.com/u/jer8jer)\
**Post date:** [March 27, 2019, 5:28pm UTC](https://forum.ansible.com/t/ansible-tail-file/29997/5 "2019-03-27T17:28:48Z")

</div>

Tested and it works. I just dont understand the syntax.
