Skip to content

Amazon Linux 2023: Invalid response from docker daemon: key \"ApiVersion\" is missing."} #1033

@tiendungitd

Description

@tiendungitd
SUMMARY

The docker_image and docker_container modules do not work in Ansible 2.15.13, I got error "Error connecting: Invalid response from docker daemon: key \"ApiVersion\" is missing."

ISSUE TYPE
  • Bug Report
COMPONENT NAME

docker_image
docker_container

ANSIBLE VERSION
ansible [core 2.15.3]
  config file = None
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.9/site-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.9.20 (main, Dec 11 2024, 00:00:00) [GCC 11.4.1 20230605 (Red Hat 11.4.1-2)] (/usr/bin/python3.9)
  jinja version = 3.1.4
  libyaml = True

COLLECTION VERSION
# /usr/lib/python3.9/site-packages/ansible_collections
Collection       Version
---------------- -------
community.docker 3.4.8

CONFIGURATION
CONFIG_FILE() = None
OS / ENVIRONMENT
NAME="Amazon Linux"
VERSION="2023"
ID="amzn"
ID_LIKE="fedora"
VERSION_ID="2023"
PLATFORM_ID="platform:al2023"
PRETTY_NAME="Amazon Linux 2023.6.20250115"
ANSI_COLOR="0;33"
CPE_NAME="cpe:2.3:o:amazon:amazon_linux:2023"
HOME_URL="https://aws.amazon.com/linux/amazon-linux-2023/"
DOCUMENTATION_URL="https://docs.aws.amazon.com/linux/"
SUPPORT_URL="https://aws.amazon.com/premiumsupport/"
BUG_REPORT_URL="https://github.com/amazonlinux/amazon-linux-2023"
VENDOR_NAME="AWS"
VENDOR_URL="https://aws.amazon.com/"
SUPPORT_END="2028-03-15"

Docker version

Client:
 Version:           25.0.5
 API version:       1.44
 Go version:        go1.22.5
 Git commit:        5dc9bcc
 Built:             Wed Aug 21 00:00:00 2024
 OS/Arch:           linux/amd64
 Context:           default

Server:
 Engine:
  Version:          25.0.6
  API version:      1.44 (minimum version 1.24)
  Go version:       go1.22.5
  Git commit:       b08a51f
  Built:            Wed Aug 21 00:00:00 2024
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.7.23
  GitCommit:        57f17b0a6295a39009d861b89e3b3b87b005ca27
 runc:
  Version:          1.1.14
  GitCommit:        2c9f5602f0ba3d9da1c2596322dfc4e156844890
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

pip list|grep docker

docker 2.6.1
docker-pycreds 0.4.0
STEPS TO REPRODUCE
- hosts: localhost
  tasks:
   - name: pull an image
     docker_image:
       name: nginx
       source: pull
EXPECTED RESULTS

Can pull the docker image

ACTUAL RESULTS

TASK [pull an image] *****************************************************************************************************
task path: /home/ec2-user/play.yml:3
redirecting (type: modules) ansible.builtin.docker_image to community.docker.docker_image
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: root
<127.0.0.1> EXEC /bin/sh -c 'echo ~root && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /root/.ansible/tmp `"&& mkdir "` echo /root/.ansible/tmp/ansible-tmp-1737712652.1796768-27374-197009959574951 `" && echo ansible-tmp-1737712652.1796768-27374-197009959574951="` echo /root/.ansible/tmp/ansible-tmp-1737712652.1796768-27374-197009959574951 `" ) && sleep 0'
redirecting (type: modules) ansible.builtin.docker_image to community.docker.docker_image
Using module file /usr/lib/python3.9/site-packages/ansible_collections/community/docker/plugins/modules/docker_image.py
<127.0.0.1> PUT /root/.ansible/tmp/ansible-local-273279cuifomg/tmp38dssglk TO /root/.ansible/tmp/ansible-tmp-1737712652.1796768-27374-197009959574951/AnsiballZ_docker_image.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-tmp-1737712652.1796768-27374-197009959574951/ /root/.ansible/tmp/ansible-tmp-1737712652.1796768-27374-197009959574951/AnsiballZ_docker_image.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python3.9 /root/.ansible/tmp/ansible-tmp-1737712652.1796768-27374-197009959574951/AnsiballZ_docker_image.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /root/.ansible/tmp/ansible-tmp-1737712652.1796768-27374-197009959574951/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
  File "/tmp/ansible_docker_image_payload_ays7ct8s/ansible_docker_image_payload.zip/ansible_collections/community/docker/plugins/module_utils/common_api.py", line 117, in __init__
    super(AnsibleDockerClientBase, self).__init__(**self._connect_params)
  File "/tmp/ansible_docker_image_payload_ays7ct8s/ansible_docker_image_payload.zip/ansible_collections/community/docker/plugins/module_utils/_api/api/client.py", line 188, in __init__
    self._version = self._retrieve_server_version()
  File "/tmp/ansible_docker_image_payload_ays7ct8s/ansible_docker_image_payload.zip/ansible_collections/community/docker/plugins/module_utils/_api/api/client.py", line 207, in _retrieve_server_version
    raise DockerException(
fatal: [localhost]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "api_version": "auto",
            "archive_path": null,
            "build": null,
            "ca_cert": null,
            "client_cert": null,
            "client_key": null,
            "debug": false,
            "docker_host": "unix://var/run/docker.sock",
            "force_absent": false,
            "force_source": false,
            "force_tag": false,
            "load_path": null,
            "name": "nginx",
            "pull": null,
            "push": false,
            "repository": null,
            "source": "pull",
            "ssl_version": null,
            "state": "present",
            "tag": "latest",
            "timeout": 60,
            "tls": false,
            "tls_hostname": null,
            "use_ssh_client": false,
            "validate_certs": false
        }
    },
    "msg": "Error connecting: Invalid response from docker daemon: key \"ApiVersion\" is missing."
}

PLAY RECAP ***************************************************************************************************************
localhost                  : ok=1    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0


Metadata

Metadata

Assignees

No one assigned

    Labels

    docker-plainplain Docker (no swarm, no compose, no stack)third-party-bugThis is a bug in some other software, not in ours

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions