You are reading an unmaintained version of the Ansible documentation. Unmaintained Ansible versions can contain unfixed security vulnerabilities (CVE). Please upgrade to a maintained version. See the latest Ansible documentation.
wait_for - Waits for a condition before continuing¶
You can wait for a set amount of time timeout, this is the default if nothing is specified or just timeout is specified. This does not produce an error.
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.
In 1.8 and later, this module can also be used to wait for active connections to be closed before continuing, useful if a node is being rotated out of a load balancer pool.
This module is also supported for Windows targets.
The list of TCP connection states which are counted as active connections.
connect_timeout
no
5
Maximum number of seconds to wait for a connection to happen before closing and retrying.
delay
no
Number of seconds to wait before starting to poll.
exclude_hosts
(added in 1.8)
no
List of hosts or IPs to ignore when looking for active TCP connections for drained state.
host
no
127.0.0.1
A resolvable hostname or IP address to wait for.
msg
(added in 2.4)
no
This overrides the normal error message from a failure to meet the required conditions.
path
(added in 1.4)
no
Path to a file on the filesystem that must exist before continuing.
port
no
Port number to poll.
search_regex
(added in 1.4)
no
Can be used to match a string in either a file or a socket connection.
Defaults to a multiline regex.
sleep
(added in 2.3)
no
1
Number of seconds to sleep between checks, before 2.3 this was hardcoded to 1 second.
state
no
started
absent
drained
present
started
stopped
Either present, started, or stopped, absent, or drained.
When checking a port started will ensure the port is open, stopped will check that it is closed, drained will check for active connections.
When 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, when used with another condition it will force an error.
When used without other conditions it is equivalent of just sleeping.
-name:sleep for 300 seconds and continue with playwait_for:timeout=300delegate_to:localhost-name:Wait 300 seconds for port 8000 to become open on the host, don't start checking for 10 secondswait_for:port:8000delay:10-name:Wait 300 seconds for port 8000 of any IP to close active connections, don't start checking for 10 secondswait_for:host:0.0.0.0port:8000delay:10state:drained-name:Wait 300 seconds for port 8000 of any IP to close active connections, ignoring connections for specified hostswait_for:host:0.0.0.0port:8000state:drainedexclude_hosts:10.2.1.2,10.2.1.3-name:Wait until the file /tmp/foo is present before continuingwait_for:path:/tmp/foo-name:Wait until the string "completed" is in the file /tmp/foo before continuingwait_for:path:/tmp/foosearch_regex:completed-name:Wait until the lock file is removedwait_for:path:/var/lock/file.lockstate:absent-name:Wait until the process is finished and pid was destroyedwait_for:path:/proc/3466/statusstate:absent-name:Output customized message when failedwait_for:path:/tmp/foostate:presentmsg:Timeout to find file /tmp/foo# Don't assume the inventory_hostname is resolvable and delay 10 seconds at start-name:Wait 300 seconds for port 22 to become open and contain "OpenSSH"wait_for:port:22host:'{{(ansible_ssh_host|default(ansible_host))|default(inventory_hostname)}}'search_regex:OpenSSHdelay:10connection:local# Same as above but you normally have ansible_connection set in inventory, which overrides 'connection'-name:Wait 300 seconds for port 22 to become open and contain "OpenSSH"wait_for:port:22host:'{{(ansible_ssh_host|default(ansible_host))|default(inventory_hostname)}}'search_regex:OpenSSHdelay:10vars:ansible_connection:local
This module is flagged as stableinterface which means that the maintainers for this module guarantee that no backward incompatible interface changes will be made.
For more information about Red Hat’s this support of this module, please
refer to this knowledge base article<https://access.redhat.com/articles/rhel-top-support-policies>