Hi,
I have submitted PR #1301. In the following I have recorded some runs of wait_for and whether the result meets my expectations:
cat connect_to_port_1234.py
import socket
import time
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((“192.168.1.125”, 1234))
print(s.getpeername())
time.sleep(30)
s.shutdown(socket.SHUT_RDWR)
s.close()
so far so good
ss -nt ‘( sport = :1234 )’
State Recv-Q Send-Q Local Address:Port Peer Address:Port
ansible lenovo.lan -i hosts -u thorsten -m wait_for -a “port=1234 state=drained”
lenovo.lan | success >> {
“changed”: false,
“elapsed”: 0,
“path”: null,
“port”: 1234,
“search_regex”: null,
“state”: “drained”
}
connection is established
python connect_to_port_1234.py &
sleep 3
ss -nt ‘( sport = :1234 )’
State Recv-Q Send-Q Local Address:Port Peer Address:Port
ESTAB 0 0 ::ffff:192.168.1.125:1234 ::ffff:192.168.1.125:56628
but isn’t noticed (should wait, does not)
ansible lenovo.lan -i hosts -u thorsten -m wait_for -a “port=1234 state=drained”
lenovo.lan | success >> {
“changed”: false,
“elapsed”: 0,
“path”: null,
“port”: 1234,
“search_regex”: null,
“state”: “drained”
}
this works around this issue
ansible lenovo.lan -i hosts -u thorsten -m wait_for -a “host=:: port=1234 state=drained”
lenovo.lan | success >> {
“changed”: false,
“elapsed”: 27,
“path”: null,
“port”: 1234,
“search_regex”: null,
“state”: “drained”
}
excludes will always be ignored
make a new connection
python connect_to_port_1234.py &
sleep 3
ss -nt ‘( sport = :1234 )’
State Recv-Q Send-Q Local Address:Port Peer Address:Port
ESTAB 0 0 ::ffff:192.168.1.125:1234 ::ffff:192.168.1.125:56629
should not wait, but does
ansible lenovo.lan -i hosts -u thorsten -m wait_for -a “host=:: port=1234 exclude_hosts=192.168.1.125 state=drained”
lenovo.lan | success >> {
“changed”: false,
“elapsed”: 27,
“path”: null,
“port”: 1234,
“search_regex”: null,
“state”: “drained”
}
make a new connection
python connect_to_port_1234.py &
sleep 3
ss -nt ‘( sport = :1234 )’
State Recv-Q Send-Q Local Address:Port Peer Address:Port
ESTAB 0 0 ::ffff:192.168.1.125:1234 ::ffff:192.168.1.125:56630
should not wait, but does
ansible lenovo.lan -i hosts -u thorsten -m wait_for -a “host=:: port=1234 exclude_hosts=::ffff:192.168.1.125 state=drained”
lenovo.lan | success >> {
“changed”: false,
“elapsed”: 27,
“path”: null,
“port”: 1234,
“search_regex”: null,
“state”: “drained”
}