Author: | Jeroen Hoekx, John Jarvis, Andrii Radyk |
---|
Waiting for a port to become available is useful for when services are not immediately available after their init scripts return - which is true of certain Java application servers. It is also useful when starting guests with the virt module and needing to pause until they are ready. This module can also be used to wait for a regex match a string to be present in a file. In 1.6 and later, this module can also be used to wait for a file to be available or absent on the filesystem.
parameter | required | default | choices | comments |
---|---|---|---|---|
delay | no | number of seconds to wait before starting to poll | ||
host | no | 127.0.0.1 | hostname or IP address to wait for | |
path | no | path to a file on the filesytem that must exist before continuing (added in Ansible 1.4) | ||
port | no | port number to poll | ||
search_regex | no | Can be used to match a string in either a file or a socket connection. Defaults to a multiline regex. (added in Ansible 1.4) | ||
state | no | started |
|
either present , started , or stopped , absent When checking a port started will ensure the port is open, stopped will check that it is closedWhen checking for a file or a search string present or started will ensure that the file or string is present before continuing, absent will check that file is absent or removed |
timeout | no | 300 | maximum number of seconds to wait for |
# wait 300 seconds for port 8000 to become open on the host, don't start checking for 10 seconds
- wait_for: port=8000 delay=10
# wait until the file /tmp/foo is present before continuing
- wait_for: path=/tmp/foo
# wait until the string "completed" is in the file /tmp/foo before continuing
- wait_for: path=/tmp/foo search_regex=completed
# wait until the lock file is removed
- wait_for: path=/var/lock/file.lock state=absent
# wait until the process is finished and pid was destroyed
- wait_for: path=/proc/3466/status state=absent
# Wait 300 seconds for port 22 to become open and contain "OpenSSH", don't start checking for 10 seconds
- local_action: wait_for port=22 host="{{ inventory_hostname }}" search_regex=OpenSSH delay=10
Note
The ability to use search_regex with a port connection was added in 1.7.