tail_grep – Tail a logfile until a regex matcher is found or a timeout triggers

Note

This module is part of the middleware_automation.common collection.

It is not included in ansible-core. To check whether it is installed, run ansible-galaxy collection list.

To install it, use: ansible-galaxy collection install middleware_automation.common.

To use it in a playbook, specify: middleware_automation.common.tail_grep.

Synopsis

  • This module is used to follow some application logfile and return successfully when a search string or regex is found; otherwise fail after a timeout.

Parameters

Parameter

Comments

delay

integer

How many seconds to wait after opening the file before starting to look for the regex.

Default: 0

from_regex

string

Backwards from end of file, lines preceeding this string will not be considered for matching regex. By default, the whole file is read. If `$` is used, start from the first line written after the file is opened.

Default: ""

path

path / required

The file on the remote system to tail.

regex

string / required

The string or regular expression to search in the file.

timeout

integer

After how many seconds to exit unsuccessfully without having found the search regex.

Default: 60

Attributes

Attribute

Support

Description

check_mode

Support: none

Can run in check_mode and return changed status prediction without modifying target, if not supported the action will be skipped.

diff_mode

Support: none

Will return details on what has changed (or possibly needs changing in check_mode), when in diff mode

platform

Platform: posix

Target OS/families that can be operated against

Examples

- name: Tail activemq log until the successful start status code is found
  ansible.builtin.tail_grep:
    path: /var/log/activemq/artemis.log
    regex: AMQ220010

Return Values

Common return values are documented here, the following are the fields unique to this module:

Key

Description

content

string

The full string that was matched by the search regex

Returned: success

Sample: "Application has been started successfully."

source

string

Actual path of file opened

Returned: success

Sample: "/var/log/messages"

Authors

  • Guido Grazioli (@guidograzioli)