SUMMARY
When running docker_container_exec module on Debian 13 managed nodes I get a non-critical warning, while the task I run in docker exec is actually being done.
There is no warning when I apply it to Debian 12 nodes, which have python 3.11 (the task itself and the controller environment are exactly the same).
And this only happens when I use stdin option to pass the command to sh, when passing it in args there is no warning.
The problem seems to be in this arm of code. Here exec_socket (a raw socket from Response object) is exposed and returned, and closed further on in a finally block.
In other arms the close() method of the Response itself is called within client.post_json_to_stream, with no warnings in that case.
The exec_socket actually has the whole Response object as its attr, so this Response object's close() method is invoked on exit, but flush() on already closed socket generates this exception.
These errors were previously ignored silently.
If I replace socket's close() with its response's close() here, the exception goes away.
exec_socket._response.close()
ISSUE TYPE
COMPONENT NAME
docker_container_exec module
ANSIBLE VERSION
ansible [core 2.18.12]
config file = .ansible.cfg
configured module search path = ['.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python3.14/site-packages/ansible
ansible collection location = .ansible/collections:/usr/share/ansible/collections
executable location = /usr/local/bin/ansible
python version = 3.14.3 (main, Feb 4 2026, 20:07:43) [GCC 15.2.0] (/usr/local/bin/python3.14)
jinja version = 3.1.6
libyaml = True
COLLECTION VERSION
Collection Version
---------------- -------
community.docker 4.8.5
CONFIGURATION
CONFIG_FILE() = .ansible.cfg
DEFAULT_HOST_LIST(.ansible.cfg) = ['inventory']
DEFAULT_JINJA2_EXTENSIONS(.ansible.cfg) = jinja2.ext.do
DUPLICATE_YAML_DICT_KEY(.ansible.cfg) = ignore
HOST_KEY_CHECKING(.ansible.cfg) = False
INTERPRETER_PYTHON(.ansible.cfg) = auto_silent
PAGER(env: PAGER) = less
OS / ENVIRONMENT
Managed node:
Debian GNU/Linux 13 (trixie)
Python 3.13.5
STEPS TO REPRODUCE
Case 1: using stdin
- hosts:
managed-node
tasks:
- community.docker.docker_container_exec:
container:
some-container
command:
sh
stdin: |
echo 123
Case 2: not using stdin
- hosts:
managed-node
tasks:
- community.docker.docker_container_exec:
container:
some-container
command:
sh -c 'echo 123'
EXPECTED RESULTS
In both cases:
TASK [community.docker.docker_container_exec] ************************************************************************************************************************************************************************
changed: [managed-node]
ACTUAL RESULTS
Case 1:
TASK [community.docker.docker_container_exec] ************************************************************************************************************************************************************************
[WARNING]: Module invocation had junk after the JSON data: Exception ignored in: <http.client.HTTPResponse object at 0x7fa4ce6bb880> Traceback (most recent call last): File "/usr/lib/python3.13/http/client.py",
line 432, in close super().close() # set "closed" flag File "/usr/lib/python3.13/http/client.py", line 445, in flush self.fp.flush() ValueError: I/O operation on closed file.
changed: [managed-node]
Case 2:
TASK [community.docker.docker_container_exec] ************************************************************************************************************************************************************************
changed: [managed-node]
SUMMARY
When running docker_container_exec module on Debian 13 managed nodes I get a non-critical warning, while the task I run in docker exec is actually being done.
There is no warning when I apply it to Debian 12 nodes, which have python 3.11 (the task itself and the controller environment are exactly the same).
And this only happens when I use
stdinoption to pass the command to sh, when passing it in args there is no warning.The problem seems to be in this arm of code. Here
exec_socket(a raw socket fromResponseobject) is exposed and returned, and closed further on in afinallyblock.In other arms the
close()method of theResponseitself is called withinclient.post_json_to_stream, with no warnings in that case.The
exec_socketactually has the wholeResponseobject as its attr, so thisResponseobject'sclose()method is invoked on exit, butflush()on already closed socket generates this exception.These errors were previously ignored silently.
If I replace socket's
close()with its response'sclose()here, the exception goes away.ISSUE TYPE
COMPONENT NAME
docker_container_exec module
ANSIBLE VERSION
COLLECTION VERSION
CONFIGURATION
OS / ENVIRONMENT
Managed node:
Debian GNU/Linux 13 (trixie)
Python 3.13.5
STEPS TO REPRODUCE
Case 1: using stdin
Case 2: not using stdin
EXPECTED RESULTS
In both cases:
ACTUAL RESULTS
Case 1:
Case 2: