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

docker_image fails to load image from local path #72

Closed
OnlyLoveOleg opened this issue Jan 21, 2021 · 8 comments · Fixed by #73
Closed

docker_image fails to load image from local path #72

OnlyLoveOleg opened this issue Jan 21, 2021 · 8 comments · Fixed by #73

Comments

@OnlyLoveOleg
Copy link

OnlyLoveOleg commented Jan 21, 2021

SUMMARY

While using docker_image to load an image from local path the step fails with "msg": "Error loading image image_name - 'NoneType' object is not iterable". This step works on ansible v2.9.2 but fails on 2.10.5 installed via pip and on develop installed from source.

playbook step:

    - name: load image from archive
      docker_image:
        name: "{{app_id}}"
        tag: latest
        push: no
        load_path: "/tmp/{{app_id}}.tar"
        force_source: yes
        force_tag: yes
        source: load

Tested on:

ansible-playbook 2.10.5
  config file = None
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.8/dist-packages/ansible
  executable location = /usr/local/bin/ansible-playbook
  python version = 3.8.5 (default, Jul 28 2020, 12:59:40) [GCC 9.3.0]

Note: I'm not sure but maybe the issue related to PR62

ISSUE TYPE
  • Bug Report
COMPONENT NAME

ansible_collections/community/general/plugins/modules/docker_image.py

ANSIBLE VERSION
ansible 2.10.5
  config file = None
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.8/dist-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 3.8.5 (default, Jul 28 2020, 12:59:40) [GCC 9.3.0]
CONFIGURATION
none all default
OS / ENVIRONMENT
  • Control machine: Ubuntu 20.04.1 LTS
  • Target node: Ubuntu 18.04.5 LTS
STEPS TO REPRODUCE

Build basic image and copy to a local path on target machine and try to load it using docker_image.

---
    - name: load image from archive
      docker_image:
        name: my_image
        tag: latest
        push: no
        load_path: "/tmp/my_image.tar"
        force_source: yes
        force_tag: yes
        source: load
EXPECTED RESULTS

The image loaded to docker on target machine. Works on ansible 2.9.2

ACTUAL RESULTS
The full traceback is:
  File "/tmp/ansible_docker_image_payload_ke8kfvfh/ansible_docker_image_payload.zip/ansible_collections/community/general/plugins/modules/docker_image.py", line 783, in load_image
fatal: [remote_ip]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "api_version": "auto",
            "archive_path": null,
            "build": null,
            "buildargs": null,
            "ca_cert": null,
            "client_cert": null,
            "client_key": null,
            "container_limits": null,
            "debug": false,
            "docker_host": "unix://var/run/docker.sock",
            "dockerfile": null,
            "force": null,
            "force_absent": false,
            "force_source": true,
            "force_tag": true,
            "http_timeout": null,
            "load_path": "/root/api-accounts-v2.tar",
            "name": "api-accounts-v2",
            "nocache": false,
            "path": null,
            "pull": null,
            "push": false,
            "repository": null,
            "rm": true,
            "source": "load",
            "ssl_version": null,
            "state": "present",
            "tag": "latest",
            "timeout": 60,
            "tls": false,
            "tls_hostname": "localhost",
            "use_tls": null,
            "validate_certs": false
        }
    },
    "msg": "Error loading image image_name - 'NoneType' object is not iterable",
    "stdout": "",
    "stdout_lines": []
}
@felixfontein
Copy link
Collaborator

It could be related to that PR, since it was backported to community.general. Which version of the Docker SDK for Python do you have installed on the target machine?

@OnlyLoveOleg
Copy link
Author

@felixfontein hope that helps

Python 3.6.9 (default, Oct  8 2020, 12:12:24)
[GCC 8.4.0] on linux

docker --version
Docker version 19.03.14, build 5eb3275d40

@felixfontein
Copy link
Collaborator

@TalLannder unfortunately not, I need the version of the Docker SDK for Python. Usually you can get it by running pip show docker or (if you have a very, very old version of it) pip show docker-py. You might need to replace pip by pip3 or the path to the pip you used to install it.

@OnlyLoveOleg
Copy link
Author

@felixfontein yeah it might be pretty old, thanks for the guidance

~# pip3 show docker-py
Name: docker-py
Version: 1.10.6
Summary: Python client for Docker.
Home-page: https://github.com/docker/docker-py/
Author: Joffrey F
Author-email: [email protected]
License: UNKNOWN
Location: /usr/local/lib/python3.6/dist-packages
Requires: requests, docker-pycreds, six, websocket-client

@felixfontein
Copy link
Collaborator

@TalLannder indeed, that's old (over four years!). In fact, docker-py (as opposed to docker) should only be used if you only have Python 2.6. It's best to uninstall it first, and then install docker(https://pypi.org/project/docker/) (pip install docker). (Uninstalling first is crucial, as having both installed leads to a broken installation of both, since they use the same internal package name.)

@felixfontein
Copy link
Collaborator

resolved_by_pr #73

@OnlyLoveOleg
Copy link
Author

@felixfontein thanks a lot sir everything works as expected with docker and the latest ansible

@felixfontein
Copy link
Collaborator

Any version of Docker SDK for Python >= 2.5.0 should work fine, as I found out while working on a fix :) But the PR, it should also work for older versions (though some of the recent improvements we've added won't work then, because it does not report the results from the API / Docker daemon).

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