# exclude\_hosts does not work as expected with state=drained

**URL:** <https://forum.ansible.com/t/exclude-hosts-does-not-work-as-expected-with-state-drained/18332>\
**Category:** Ansible Developer\
**Created:** [May 28, 2015, 3:52pm UTC](https://forum.ansible.com/t/exclude-hosts-does-not-work-as-expected-with-state-drained/18332 "2015-05-28T15:52:26Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thorsten](https://avatars.discourse-cdn.com/v4/letter/t/d2c977/32.png) [@Thorsten](https://forum.ansible.com/u/Thorsten)\
**Post date:** [May 28, 2015, 3:52pm UTC](https://forum.ansible.com/t/exclude-hosts-does-not-work-as-expected-with-state-drained/18332/1 "2015-05-28T15:52:26Z")

</div>

Hi,

I have submitted [PR #1301](https://github.com/ansible/ansible-modules-core/pull/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”  
}
