Ansible (14) wait_for module, ansiblewait_for
Module description
When you use service to start tomcat or database, are they actually starting? Do you want to confirm this?
This is what the wait_for module does.Wait for a thing to happen and continue. It can wait for a port to be occupied, and then do the following, Or do another thing after a certain time-out.
Common Parameters
Parameter Name |
Required? |
Default Value |
Option |
Description |
Connect_timeout |
No |
5 |
|
The waiting time before the next event occurs, in seconds. |
Delay |
No |
|
|
Latency: the number of seconds before the next task. |
Host |
No |
127.0.0.1 |
|
Host that executes this module |
Path |
No |
|
|
If a file exists in the file system, the next step is to continue. |
Port |
No |
|
|
Port number, such as 8080 |
State |
No |
Started |
Present/started/stopped/absent |
When the object is a port, the start State ensures that the port is opened, and the stoped State determines that the port is closed. When the object is a file, the present or started confirms that the file exists, the absent will confirm that the file does not exist. |
Case
# Check port 8000 on the current host after 10 seconds until the port is started-wait_for: port = 8000 delay = 10 # Check path =/tmp/foo until the file exists-wait_for: path =/tmp/foo # Until/var/lock/file. after the lock is removed, continue-wait_for: path =/var/lock/file. lock state = absent # continue until/proc/3466/status is removed-wait_for: path =/proc/3466/status state = absent
All the modules used in the previous homework have been explained.