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

New requests release breaks docker version check #863

Closed
daniel-mizsak opened this issue May 21, 2024 · 7 comments · Fixed by #864
Closed

New requests release breaks docker version check #863

daniel-mizsak opened this issue May 21, 2024 · 7 comments · Fixed by #864

Comments

@daniel-mizsak
Copy link

SUMMARY

requests==2.32.0 introduced a bug that affects the docker pip package.

This results in community.docker.docker_container_info being broken at the moment. Other modules might be affected too.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

community.docker.docker_container_info

ANSIBLE VERSION
ansible [core 2.16.7]
  python version = 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0]
  jinja version = 3.1.3
  libyaml = True
COLLECTION VERSION
Collection       Version
---------------- -------
community.docker 3.10.1
STEPS TO REPRODUCE

I used ansible to install the docker pip package:

- name: Install docker sdk for python.
  ansible.builtin.pip:
    name:
      - docker
      - docker-compose
    state: latest

And since the package did not specify an exact requests version it pulled down the latest 2.32.0.

Later in the playbook trying to get information about a docker container:

- name: Check if the node-exporter container is running.
  community.docker.docker_container_info:
    name: node-exporter
  register: node_exporter_container

Results in an error:

The full traceback is:
  File "/tmp/ansible_community.docker.docker_container_info_payload_3ep3raeb/ansible_community.docker.docker_container_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_container_info_payload_3ep3raeb/ansible_community.docker.docker_container_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_container_info_payload_3ep3raeb/ansible_community.docker.docker_container_info_payload.zip/ansible_collections/community/docker/plugins/module_utils/_api/api/client.py", line 212, in _retrieve_server_version
    raise DockerException(
fatal: [host_machine]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "api_version": "auto",
            "ca_path": null,
            "client_cert": null,
            "client_key": null,
            "debug": false,
            "docker_host": "unix:///var/run/docker.sock",
            "name": "node-exporter",
            "ssl_version": null,
            "timeout": 60,
            "tls": false,
            "tls_hostname": null,
            "use_ssh_client": false,
            "validate_certs": false
        }
    },
    "msg": "Error connecting: Error while fetching server API version: Not supported URL scheme http+docker"
}
FIX

I was able to fix it temporarily by running:

sudo pip3 uninstall requests
sudo pip3 install requests==2.31.0

Warning

For me it was necessary to use sudo for both the installation and uninstall as ansible is also running as root, so that I target packages in the same location.

A permanent fix should also arrive soon, just wanted to document the issue in case someone encounters it in the meantime.

@felixfontein
Copy link
Collaborator

Are you sure that you were using community.docker.docker_container_info from community.docker 3.10.1? I'm asking because 3.10.1 got released yesterday with a fix (#861) that prevents this problem with requests 2.32.0. (It might no longer work with requests 2.32.2, see psf/requests#6707 (comment), I'll create another update for that once that's out...)

The only modules that still have this problem are the modules using Docker Swarm, and the deprecated docker_compose module.

@felixfontein
Copy link
Collaborator

#864 contains a fix for requests 2.32.2+; the current fix will stop working with 2.32.2.

@felixfontein
Copy link
Collaborator

(community.docker.docker_container_info hasn't been relying on Docker SDK for Python since community.docker 3.0.0 btw. Instead it's using code from a vendored copy of that SDK.)

@daniel-mizsak
Copy link
Author

daniel-mizsak commented May 22, 2024

Thanks for the quick reply.

After checking again, I did have another installation of ansible collections at ~/.ansible with an older community.docker version, but after removing it and ensuring that I am using community.docker 3.10.1 I was still able to reproduce the issue.

If I skip the Install docker sdk for python. job the Check if the node-exporter container is running. runs successfully as it uses an old "built-in" version of requests, but installing the docker pip package also installs requests 3.32.2 as the "built-in" version is older than 2.26.

@felixfontein
Copy link
Collaborator

community.docker 3.10.1 does not work with requests 2.32.2, it only works with requests 3.32.0 and 3.32.1. You need community.docker 3.10.2, which works with all requests 2.32.x releases.

@daniel-mizsak
Copy link
Author

Alright, it worked indeed. 👍

But this also means that the new community.docker version will only be part of the next ansible release, so for now one would have to run ansible-galaxy collection install -U community.docker after a fresh ansible installation.

@felixfontein
Copy link
Collaborator

Yes, that's unfortunately needed. Also you need to make sure to remove the manually installed version once a new ansible version is out, otherwise the manually installed version will hide the one from ansible...

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

Successfully merging a pull request may close this issue.

2 participants