Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

community.docker.docker_host_info : Error connecting: Error while fetching server API version: Not supported URL scheme http+docker #868

Closed
D0wn3r opened this issue May 22, 2024 · 22 comments

Comments

@D0wn3r
Copy link

D0wn3r commented May 22, 2024

SUMMARY

I'm trying to get docker info through Ansible with the module community.docker.docker_host_info but it doesn't work anymore.
It's on a fresh install (fresh ubuntu 22.04 with docker 26.0.X and also tried with 25.0.4)

ISSUE TYPE
  • Bug Report
COMPONENT NAME
ANSIBLE VERSION
ansible [core 2.15.4]
  config file = /home/simco-dev/PROJECTS/pca/ansible.cfg
  configured module search path = ['/home/simco-dev/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.10/dist-packages/ansible
  ansible collection location = /home/simco-dev/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.10.14 (main, Apr  6 2024, 18:45:05) [GCC 9.4.0] (/usr/bin/python3.10)
  jinja version = 3.1.2
  libyaml = True
COLLECTION VERSION
# /usr/local/lib/python3.10/dist-packages/ansible_collections
Collection        Version
----------------- -------
community.general 7.4.0

# <home_path>/.ansible/collections/ansible_collections
Collection       Version
---------------- -------
community.docker 3.10.2
CONFIGURATION
CONFIG_FILE() = <path>/ansible.cfg
DEFAULT_ROLES_PATH(<path>/ansible.cfg) = ['<path>/ansible-common-roles']
HOST_KEY_CHECKING(<path>/ansible.cfg) = False
PAGER(env: PAGER) = less
OS / ENVIRONMENT

Fresh instance ubuntu 22.04 from the cloud provider Scaleway

STEPS TO REPRODUCE

with docker_version: "5:25.0.4-1ubuntu.20.04focal"

---
- name: Install required system packages
  ansible.builtin.apt:
      pkg:
          - ca-certificates=20230311ubuntu0.22.04.1
          - curl=7.81.0-1ubuntu1.16
          - python3-pip=22.0.2+dfsg-1ubuntu0.4
          - gnupg=2.2.27-3ubuntu2.1
      state: present
      update_cache: true
  become: true

- name: Add Docker GPG apt Key
  ansible.builtin.apt_key:
      url: https://download.docker.com/linux/ubuntu/gpg
      state: present
  become: true

- name: Add Docker Repository
  ansible.builtin.apt_repository:
      repo: deb https://download.docker.com/linux/ubuntu focal stable
      state: present
  become: true

- name: Update apt and install docker-ce
  ansible.builtin.apt:
      name:
          - "docker-ce={{ docker_version }}"
          - "docker-ce-cli={{ docker_version }}"
      state: present
      allow_downgrade: true
      force: true
  become: true

- name: Install SDK docker and jsondiff (python)
  ansible.builtin.pip:
      name:
          - docker
          - jsondiff
      state: present
  become: true

- name: Check if Swarm cluster exists
  become: true
  community.docker.docker_host_info:
  register: docker_info
EXPECTED RESULTS

I expect to get docker info

ACTUAL RESULTS

This error happened on my 3 servers

The full traceback is:
  File "/tmp/ansible_community.docker.docker_host_info_payload_316ufw33/ansible_community.docker.docker_host_info_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_community.docker.docker_host_info_payload_316ufw33/ansible_community.docker.docker_host_info_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_community.docker.docker_host_info_payload_316ufw33/ansible_community.docker.docker_host_info_payload.zip/ansible_collections/community/docker/plugins/module_utils/_api/api/client.py", line 212, in _retrieve_server_version
    raise DockerException(
fatal: [swarm-01]: FAILED! => {
    "can_talk_to_docker": false,
    "changed": false,
    "invocation": {
        "module_args": {
            "api_version": "auto",
            "ca_cert": null,
            "client_cert": null,
            "client_key": null,
            "containers": false,
            "containers_all": false,
            "containers_filters": null,
            "debug": false,
            "disk_usage": false,
            "docker_host": "unix://var/run/docker.sock",
            "images": false,
            "images_filters": null,
            "networks": false,
            "networks_filters": null,
            "ssl_version": null,
            "timeout": 60,
            "tls": false,
            "tls_hostname": null,
            "use_ssh_client": false,
            "validate_certs": false,
            "verbose_output": false,
            "volumes": false,
            "volumes_filters": null
        }
    },
    "msg": "Error connecting: Error while fetching server API version: Not supported URL scheme http+docker"
}
@D0wn3r
Copy link
Author

D0wn3r commented May 22, 2024

Maybe this issue is because of the requests upgrade
docker/docker-py#3256

@D0wn3r
Copy link
Author

D0wn3r commented May 22, 2024

if I force requests package version 2.31.0, it works

@felixfontein
Copy link
Collaborator

I guess you are using community.docker before 3.10.2. (You only provided the community.general version.) Either upgrade community.docker to the latest version (it fixed this issue yesterday), or stick to requests < 2.32.0.

Also please consider searching for similar error messages in the repository before creating a new issue the next time. You would have found two closed issues.

@D0wn3r
Copy link
Author

D0wn3r commented May 23, 2024

I guess you are using community.docker before 3.10.2. (You only provided the community.general version.) Either upgrade community.docker to the latest version (it fixed this issue yesterday), or stick to requests < 2.32.0.

Also please consider searching for similar error messages in the repository before creating a new issue the next time. You would have found two closed issues.

# <path>/.ansible/collections/ansible_collections
Collection       Version
---------------- -------
community.docker 3.10.2

I'm using the latest version

@timon-michel-scopevisio

Same here, i just did a completely fresh install and this issue appears.
community.docker is on the same version: 3.10.2

I did, however, notice that i am using community.docker.docker_compose, which is deprecated (without deprecation warning on the docs), and i am not getting the same error on community.docker.docker_compose_v2.

Interestingly this issue is indexed by google, whereas the other two you are referring to are not

@felixfontein
Copy link
Collaborator

I did, however, notice that i am using community.docker.docker_compose, which is deprecated (without deprecation warning on the docs),

Apparently the latest Ansible docs weren't rebuilt for the Ansible 9.6.0 release. The docs here: https://docs.ansible.com/ansible/devel/collections/community/docker/docker_compose_module.html#deprecated and here: https://ansible-collections.github.io/community.docker/branch/main/docker_compose_module.html#deprecated show that warning.

and i am not getting the same error on community.docker.docker_compose_v2.

Which is not surprising, since that module calls the docker compose CLI tool. No Python requests or Docker SDK for Python involved.

@felixfontein
Copy link
Collaborator

I guess you are using community.docker before 3.10.2. (You only provided the community.general version.) Either upgrade community.docker to the latest version (it fixed this issue yesterday), or stick to requests < 2.32.0.
Also please consider searching for similar error messages in the repository before creating a new issue the next time. You would have found two closed issues.

# <path>/.ansible/collections/ansible_collections
Collection       Version
---------------- -------
community.docker 3.10.2

I'm using the latest version

In that case I have no idea what's going wrong in your case, since everything works both fine in CI and on my local machine with the latest requests.

Are you using a special way to talk to the Docker daemon, or are you using the default way (default Unix socket)?

@felixfontein
Copy link
Collaborator

@D0wn3r just to make sure, are you sure that you got the error with docker_host_info on community.docker 3.10.2? Or did you got it with some other modules, for example docker_swarm or docker_swarm_*?

@felixfontein
Copy link
Collaborator

@timon-michel-scopevisio also note that docker_compose requires Docker SDK for Python < 7.0.0 (it will crash and burn with 7.0.0), and that will never receive a fix for requests 2.32.x. If you want to stick to using docker-compose v1 (that has been End of Life for several years now) with the docker_compose module, you have to make sure you use requests < 2.32.0.

Better use docker_compose_v2 though :)

@felixfontein
Copy link
Collaborator

I did, however, notice that i am using community.docker.docker_compose, which is deprecated (without deprecation warning on the docs),

FYI, the Ansible 9 docsite has been rebuilt, now it's also in the latest docs: https://docs.ansible.com/ansible/latest/collections/community/docker/docker_compose_module.html#deprecated

@D0wn3r
Copy link
Author

D0wn3r commented May 24, 2024

@D0wn3r just to make sure, are you sure that you got the error with docker_host_info on community.docker 3.10.2? Or did you got it with some other modules, for example docker_swarm or docker_swarm_*?

@felixfontein
I will try but in my role, I launch a docker_host_info before any other docker_swarm*

@D0wn3r
Copy link
Author

D0wn3r commented May 24, 2024

I guess you are using community.docker before 3.10.2. (You only provided the community.general version.) Either upgrade community.docker to the latest version (it fixed this issue yesterday), or stick to requests < 2.32.0.
Also please consider searching for similar error messages in the repository before creating a new issue the next time. You would have found two closed issues.

# <path>/.ansible/collections/ansible_collections
Collection       Version
---------------- -------
community.docker 3.10.2

I'm using the latest version

In that case I have no idea what's going wrong in your case, since everything works both fine in CI and on my local machine with the latest requests.

Are you using a special way to talk to the Docker daemon, or are you using the default way (default Unix socket)?

I have nothing special. It's a fresh install. I will try more tests. I expected to fall on people that have the same issue

@D0wn3r
Copy link
Author

D0wn3r commented May 24, 2024

I tried again today and it works like a charm ... I close this issue so I don't know what did change since my last test. I'm not able to make it bugs

@D0wn3r D0wn3r closed this as completed May 24, 2024
glimchb added a commit to opiproject/opi-poc that referenced this issue May 27, 2024
OmarMoustafaElsherbiny added a commit to OmarMoustafaElsherbiny/AWS-Wordpress-Solution that referenced this issue May 28, 2024
…s package

A bug in the requests package v2.32.0 that causes the CI and Ansible docker module to fail with "Error connecting: Error while fetching server API version: Not supported URL scheme http+docker" msg, to reconcile this we either have to downgrade and pin the pip docker package to v7.1.0 or the requests packages to <2.32 until an offical fix is released

Source 1: docker/docker-py#3256

Source 2:ansible-collections/community.docker#868

Source 3: https://www.reddit.com/r/docker/comments/1cwx3pg/issue_with_python_docker_sdk/

All these sources are within the same timeframe
@Hennns
Copy link

Hennns commented May 29, 2024

I suspect this is related to the latest patch release of requests, 2.32.2.

I've tested with the following:
(Using both docker_host_info and docker_container, but the results are the same for both)

ansible [core 2.16.7]
config file = None
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python3.11/site-packages/ansible
ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/local/bin/ansible
python version = 3.11.7 (/usr/bin/python3.11)
jinja version = 3.1.4
libyaml = True

ansible-galaxy collection list
...
community.docker 3.10.1
community.general 8.6.1
...

On the managed node:
pip list installed | grep docker
docker 7.1.0

  • pip3 install requests==2.32.2 -> does not work
  • pip3 install requests==2.32.1 -> works
  • pip3 install requests==2.32.0 -> works
  • pip3 install requests==2.31.0 -> works

@felixfontein
Copy link
Collaborator

community.docker 3.10.1 only works with requests up to 2.32.1, it does not work with requests 2.32.2 and further. You need community.docker 3.10.2 for that.

@Hennns
Copy link

Hennns commented May 29, 2024

Ahh, I was just installing everything with (basically) 'pip install ansible==9.6.0 ', which of course has 3.10.1 of community.docker.
Then like an idiot I assumed I was using the latest and greatest.

Thank you for the clarification! :)

@felixfontein
Copy link
Collaborator

You unfortunately have to wait for Ansible 9.7.0 then, which should be there in a bit less than 3 weeks. Or wait for Ansible 10.0.0, which is likely out next Tuesday (assuming that no blockers show up). Ansible 10.0.0rc1 (released two days ago) already has community.docker 3.10.3.

@mrsiesta
Copy link

mrsiesta commented Jun 4, 2024

Verified updating the community.docker version resolved the issue for me.

In case someone is wondering how to do that:
ansible-galaxy collection install community.docker

@felixfontein
Copy link
Collaborator

Ansible 10.0.0 is out now btw (uploaded to PyPI 33 minutes ago =) ).

@Valeronlol
Copy link

It looks like it was fixed in community.docker:3.10.2, current stable version is 3.10.3.
So we just need to upgrade community.docker version to latest, like that: ansible-galaxy collection install community.docker --upgrade

@bbezak
Copy link

bbezak commented Jun 11, 2024

Ansible 10.0.0 is out now btw (uploaded to PyPI 33 minutes ago =) ).

Should we also update to 3.10.3 in Ansible 9 ? - https://github.com/ansible-community/ansible-build-data/blob/main/9/ansible-9.6.1.yaml#L89-L91
https://github.com/ansible-community/ansible-build-data/blob/main/9/ansible-9.build#L33

openstack-mirroring pushed a commit to openstack/kolla that referenced this issue Jun 11, 2024
Periodic jobs are failing because Zuul Ansible executor runs with
Ansible 8 which uses community.docker collection that needs requests<2.32.
Revert this patch when Zuul supports Ansible 10, and/or Ansible 9 gets
fixed community.docker collection. [1]

[1] ansible-collections/community.docker#868

Related-Bug: #2066364
Change-Id: I1dda73b0bc9a9f57ec8fda3f2234449b04906410
openstack-mirroring pushed a commit to openstack/openstack that referenced this issue Jun 11, 2024
* Update kolla from branch 'master'
  to 428f37124986019bedc897469f9b1f3470b62082
  - CI: Pin requests to <2.32 for publish jobs
    
    Periodic jobs are failing because Zuul Ansible executor runs with
    Ansible 8 which uses community.docker collection that needs requests<2.32.
    Revert this patch when Zuul supports Ansible 10, and/or Ansible 9 gets
    fixed community.docker collection. [1]
    
    [1] ansible-collections/community.docker#868
    
    Related-Bug: #2066364
    Change-Id: I1dda73b0bc9a9f57ec8fda3f2234449b04906410
@felixfontein
Copy link
Collaborator

@bbezak the next regular Ansible 9 release (should be 9.7.0, and should be released in ~one week) will include it. Ansible 9.6.1 has been a hotfix for 9.6.0 to remove suspicious Windows binaries that were accidentally included in two collections. There was no other change in 9.6.1 compared to 9.6.0.

openstack-mirroring pushed a commit to openstack/kolla that referenced this issue Jun 12, 2024
Periodic jobs are failing because Zuul Ansible executor runs with
Ansible 8 which uses community.docker collection that needs requests<2.32.
Revert this patch when Zuul supports Ansible 10, and/or Ansible 9 gets
fixed community.docker collection. [1]

[1] ansible-collections/community.docker#868

Related-Bug: #2066364
Change-Id: I1dda73b0bc9a9f57ec8fda3f2234449b04906410
(cherry picked from commit 428f371)
openstack-mirroring pushed a commit to openstack/kolla that referenced this issue Jun 12, 2024
Periodic jobs are failing because Zuul Ansible executor runs with
Ansible 8 which uses community.docker collection that needs requests<2.32.
Revert this patch when Zuul supports Ansible 10, and/or Ansible 9 gets
fixed community.docker collection. [1]

[1] ansible-collections/community.docker#868

Related-Bug: #2066364
Change-Id: I1dda73b0bc9a9f57ec8fda3f2234449b04906410
(cherry picked from commit 428f371)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants