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?
Rename the log before you start, then you have a clean log file.
I found a solution on stacktrace:
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
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
template:
src: startup-systemd.j2
dest: /etc/systemd/system/confluence.service
register: service
- name: Reload service definition
shell: 'systemctl daemon-reload'
when: service.changed
- name: Ensure service is enabled
service:
name: confluence
enabled: yes
state: started
- name: Wait for JVM to come up
wait_for:
host: localhost
port: 8090
delay: 2
timeout: 120
state: started
Tested and it works. I just dont understand the syntax.