Ansible Invalid response from docker daemon: key \"ApiVersion\" is missing

Hi,

While trying to deploy docker container we are facing:
FAILED! => {“changed”: false, “msg”: “Error connecting: Invalid response from docker daemon: key "ApiVersion" is missing.”}

Please give some suggestions if any one encounter this kind of issue.

Hard to tell since you provide almost no information. If you’re using Amazon Linux 2023 and certain modules/plugins from the community.docker collection, you might be hit by a bug in Amazon Linux 2023: Amazon Linux 2023: Invalid response from docker daemon: key \"ApiVersion\" is missing."} · Issue #1033 · ansible-collections/community.docker · GitHub

Earlier, I was able to restart and redeploy Docker containers through Ansible without any issues. However, suddenly, we’re encountering an API version issue, and we’re no longer able to start or redeploy containers on the target machines.

This our ansible and python version:
ansible [core 2.11.3]
config file = /etc/ansible/ansible.cfg
configured module search path = [‘/home/user/.ansible/plugins/modules’, ‘/usr/share/ansible/plugins/modules’]
ansible python module location = /usr/local/lib/python3.6/site-packages/ansible
ansible collection location = /home/user/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/local/bin/ansible
python version = 3.6.8 (default, Nov 15 2024, 08:11:39) [GCC 8.5.0 20210514 (Red Hat 8.5.0-22)]
jinja version = 2.10.1
libyaml = True

Here is an example of the playbook I used to retrieve Docker information from the target machines.

  • name: Test Ansible-Docker Connection
    hosts: all
    gather_facts: no
    tasks:
    • name: Get Docker Info
      community.docker.docker_host_info:
      register: docker_info

    • name: Show Docker Info
      debug:
      var: docker_info

fatal: [IP: FAILED! => {“ansible_facts”: {“discovered_interpreter_python”: “/usr/libexec/platform-python”}, “can_talk_to_docker”: false, “changed”: false, “msg”: “Error connecting: Invalid response from docker daemon: key "ApiVersion" is missing.”}
fatal: [IP]: FAILED! => {“ansible_facts”: {“discovered_interpreter_python”: “/usr/libexec/platform-python”}, “can_talk_to_docker”: false, “changed”: false, “msg”: “Error connecting: Invalid response from docker daemon: key "ApiVersion" is missing.”}
fatal: [IP]: FAILED! => {“ansible_facts”: {“discovered_interpreter_python”: “/usr/libexec/platform-python”}, “can_talk_to_docker”: false, “changed”: false, “msg”: “Error connecting: Invalid response from docker daemon: key "ApiVersion" is missing.”}
fatal: [IP]: FAILED! => {“ansible_facts”: {“discovered_interpreter_python”: “/usr/libexec/platform-python”}, “can_talk_to_docker”: false, “changed”: false, “msg”: “Error connecting: Invalid response from docker daemon: key "ApiVersion" is missing.”}
fatal: [IP]: FAILED! => {“ansible_facts”: {“discovered_interpreter_python”: “/usr/libexec/platform-python”}, “can_talk_to_docker”: false, “changed”: false, “msg”: “Error connecting: Invalid response from docker daemon: key "ApiVersion" is missing.”}
fatal: [IP]: FAILED! => {“can_talk_to_docker”: false, “changed”: false, “msg”: “Error connecting: Invalid response from docker daemon: key "ApiVersion" is missing.”}
fatal: [IP]: FAILED! => {“can_talk_to_docker”: false, “changed”: false, “msg”: “Error connecting: Invalid response from docker daemon: key "ApiVersion" is missing.”}
fatal: [IP]: FAILED! => {“can_talk_to_docker”: false, “changed”: false, “msg”: “Error connecting: Invalid response from docker daemon: key "ApiVersion" is missing.”}
fatal: [IP]: FAILED! => {“can_talk_to_docker”: false, “changed”: false, “msg”: “Error connecting: Invalid response from docker daemon: key "ApiVersion" is missing.”}
fatal: [IP]: FAILED! => {“can_talk_to_docker”: false, “changed”: false, “msg”: “Error connecting: Invalid response from docker daemon: key "ApiVersion" is missing.”}