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

podman-docker incompatibilities in common_cli.py: KeyError: 'ApiVersion' #891

Open
pavelzw opened this issue Jun 23, 2024 · 5 comments
Open
Labels
not-a-bug This is not a bug, but a problem with the user's environment, a wrong usage, or intended behavior

Comments

@pavelzw
Copy link

pavelzw commented Jun 23, 2024

SUMMARY

The plugin fails when using podman-docker because it expects a specific format output format in docker version --format '{{ json . }}' which is not supported by `podman-docker:

self.docker_api_version_str = self._version['Server']['ApiVersion']

$ docker version --format '{{ json . }}' | jq
Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg.
{
  "Client": {
    "APIVersion": "5.1.1",
    "Version": "5.1.1",
    "GoVersion": "go1.22.3",
    "GitCommit": "",
    "BuiltTime": "Tue Jun  4 02:00:00 2024",
    "Built": 1717459200,
    "OsArch": "linux/amd64",
    "Os": "linux"
  }
}
ISSUE TYPE
  • Bug Report
COMPONENT NAME

community.docker/plugins/module_utils/common_cli.py

ANSIBLE VERSION
ansible [core 2.16.6]
  config file = None
  configured module search path = ['/Users/pavel/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = .../.pixi/envs/default/lib/python3.12/site-packages/ansible
  ansible collection location = /Users/pavel/.ansible/collections:/usr/share/ansible/collections
  executable location = .../.pixi/envs/default/bin/ansible
  python version = 3.12.3 | packaged by conda-forge | (main, Apr 15 2024, 18:35:20) [Clang 16.0.6 ] (.../.pixi/envs/default/bin/python3.12)
  jinja version = 3.1.4
  libyaml = True
COLLECTION VERSION
❯ ansible-galaxy collection list community.docker

# /Users/pavel/.ansible/collections/ansible_collections
Collection       Version
---------------- -------
community.docker 3.10.4 

# .../.pixi/envs/default/lib/python3.12/site-packages/ansible_collections
Collection       Version
---------------- -------
community.docker 3.9.0  
CONFIGURATION
CONFIG_FILE() = None
OS / ENVIRONMENT

macOS M1

target OS: fedora 40 with podman and podman-docker installed

$ dnf list installed | grep podman
podman.x86_64                                 5:5.1.1-1.fc40             @updates
podman-compose.noarch                         1.1.0-1.fc40               @updates
podman-docker.noarch                          5:5.1.1-1.fc40             @updates
STEPS TO REPRODUCE
  • Install podman, podman-docker
  • create a docker-compose on the target machine
    - name: Install packages
      ansible.builtin.dnf:
        name:
          - podman
          - podman-docker
        state: present
    - name: Install docker-compose
      ansible.builtin.get_url:
        url: https://github.com/docker/compose/releases/download/v2.28.0/docker-compose-linux-x86_64
        dest: /usr/local/bin/docker-compose
        mode: '0755'
        checksum: sha256:359043c2336e243662d7038c3edfeadcd5b9fc28dabe6973dbaecf48c0c1f967
    - name: Start docker container
      community.docker.docker_compose_v2:
        project_src: path/to/docker-dir
        state: present
EXPECTED RESULTS

This should go through

ACTUAL RESULTS
module_stdout: |-
    Traceback (most recent call last):
      File "/home/pavel/.ansible/tmp/ansible-tmp-1719100884.715269-51508-141209575582183/AnsiballZ_docker_compose_v2.py", line 107, in <module>
        _ansiballz_main()
      File "/home/pavel/.ansible/tmp/ansible-tmp-1719100884.715269-51508-141209575582183/AnsiballZ_docker_compose_v2.py", line 99, in _ansiballz_main
        invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
      File "/home/pavel/.ansible/tmp/ansible-tmp-1719100884.715269-51508-141209575582183/AnsiballZ_docker_compose_v2.py", line 47, in invoke_module
        runpy.run_module(mod_name='ansible_collections.community.docker.plugins.modules.docker_compose_v2', init_globals=dict(_module_fqn='ansible_collections.community.docker.plugins.modules.docker_compose_v2', _modlib_path=modlib_path),
      File "<frozen runpy>", line 226, in run_module
      File "<frozen runpy>", line 98, in _run_module_code
      File "<frozen runpy>", line 88, in _run_code
      File "/tmp/ansible_community.docker.docker_compose_v2_payload_s26629r8/ansible_community.docker.docker_compose_v2_payload.zip/ansible_collections/community/docker/plugins/modules/docker_compose_v2.py", line 642, in <module>
      File "/tmp/ansible_community.docker.docker_compose_v2_payload_s26629r8/ansible_community.docker.docker_compose_v2_payload.zip/ansible_collections/community/docker/plugins/modules/docker_compose_v2.py", line 626, in main
      File "/tmp/ansible_community.docker.docker_compose_v2_payload_s26629r8/ansible_community.docker.docker_compose_v2_payload.zip/ansible_collections/community/docker/plugins/module_utils/common_cli.py", line 303, in __init__
      File "/tmp/ansible_community.docker.docker_compose_v2_payload_s26629r8/ansible_community.docker.docker_compose_v2_payload.zip/ansible_collections/community/docker/plugins/module_utils/common_cli.py", line 83, in __init__
    KeyError: 'ApiVersion'
@pavelzw pavelzw changed the title podman-docker incompatibilities in common_cli.py: `KeyError: 'ApiVersion' podman-docker incompatibilities in common_cli.py: KeyError: 'ApiVersion' Jun 23, 2024
@felixfontein
Copy link
Collaborator

This is not a bug in this collection since we do not support podman-docker. If something works fine with podman-docker you're lucky, but if it does not it's not a bug for this collection.

Your playbook doesn't look like it could ever work anyway:

  1. You don't seem to be starting podman's docker socket. With that docker-compose won't be able to access podman as Docker.
  2. You are installing the docker-compose binary, but the docker_compose_v2 module needs the Compose plugin. It uses docker compose instead of docker-compose to access Compose.

@felixfontein felixfontein added the not-a-bug This is not a bug, but a problem with the user's environment, a wrong usage, or intended behavior label Jun 23, 2024
@pavelzw
Copy link
Author

pavelzw commented Jun 23, 2024

You don't seem to be starting podman's docker socket. With that docker-compose won't be able to access podman as Docker.

I am, only forgot to include this in the reproducer

It uses docker compose instead of docker-compose to access Compose.

actually, docker compose also invokes the docker-compose binary in some way on my system 🤔

@felixfontein
Copy link
Collaborator

It uses docker compose instead of docker-compose to access Compose.

actually, docker compose also invokes the docker-compose binary in some way on my system 🤔

Then that aspect should be fine, but as long as podman version does not provide the Docker API version, the module will still not work. (The module also expects docker info to provide the Compose plugin's version; podman info doesn't seem to do that, so this would probably be the next thing that fails.)

@ch0fe
Copy link

ch0fe commented Jul 19, 2024

I believe it would be valuable if podman could also be supported by this module.
What would be required for the module to test for capabilities rather than a version string?

@felixfontein
Copy link
Collaborator

Skipping the API version check is pretty easy to implement, but as I wrote above, the big problem will be the capabilities based Compose check, which doesn't work since podman info isn't providing that information at all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
not-a-bug This is not a bug, but a problem with the user's environment, a wrong usage, or intended behavior
Projects
None yet
Development

No branches or pull requests

3 participants