ansible-collections / community.docker

Community Docker Collection for Ansible: modules and plugins for working with Docker
https://galaxy.ansible.com/ui/repo/published/community/docker/
GNU General Public License v3.0
200 stars 113 forks source link

fails on mac os for this project #214

Closed SamYuan1990 closed 3 years ago

SamYuan1990 commented 3 years ago
SUMMARY

Seems this module fails on Mac

ISSUE TYPE
COMPONENT NAME
ANSIBLE VERSION
ansible --version
ansible 2.10.3
  config file = None
  configured module search path = ['/Users/yuanyi/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/Cellar/ansible/2.10.4/libexec/lib/python3.9/site-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 3.9.1 (default, Sep 20 2021, 19:20:38) [Clang 12.0.0 (clang-1200.0.32.28)]
COLLECTION VERSION
Collection       Version
---------------- -------
community.docker 1.9.1  
CONFIGURATION
COMMAND_WARNINGS(/ansible.cfg) = False
DEFAULT_HOST_LIST(/ansible.cfg) = ['/hosts']
DEFAULT_LOG_PATH(/ansible.cfg) = /ansible.log
HOST_KEY_CHECKING(/ansible.cfg) = False
OS / ENVIRONMENT
uname -a
Darwin 192.168.1.6 19.6.0 Darwin Kernel Version 19.6.0: Sun Jul  5 00:43:10 PDT 2020; root:xnu-6153.141.1~9/RELEASE_X86_64 x86_64
STEPS TO REPRODUCE
---
- name: traffic task
  community.docker.docker_container:
    name: observer
    image: busybox
EXPECTED RESULTS

start a busybox

ACTUAL RESULTS
<192.168.1.6> ESTABLISH SSH CONNECTION FOR USER: None
<192.168.1.6> SSH: EXEC ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/Users/yuanyi/.ansible/cp/c3dbd47e8c 192.168.1.6 '/bin/sh -c '"'"'echo ~ && sleep 0'"'"''
<192.168.1.6> (0, b'/Users/yuanyi\n', b'OpenSSH_8.1p1, LibreSSL 2.7.3\r\ndebug1: Reading configuration data /Users/yuanyi/.ssh/config\r\ndebug1: /Users/yuanyi/.ssh/config line 1: Applying options for *\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 47: Applying options for *\r\ndebug2: resolve_canonicalize: hostname 192.168.1.6 is address\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 43920\r\ndebug3: mux_client_request_session: session request sent\r\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 0\r\n')
<192.168.1.6> ESTABLISH SSH CONNECTION FOR USER: None
<192.168.1.6> SSH: EXEC ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/Users/yuanyi/.ansible/cp/c3dbd47e8c 192.168.1.6 '/bin/sh -c '"'"'( umask 77 && mkdir -p "` echo /Users/yuanyi/.ansible/tmp `"&& mkdir "` echo /Users/yuanyi/.ansible/tmp/ansible-tmp-1632149240.549101-44053-164536349728609 `" && echo ansible-tmp-1632149240.549101-44053-164536349728609="` echo /Users/yuanyi/.ansible/tmp/ansible-tmp-1632149240.549101-44053-164536349728609 `" ) && sleep 0'"'"''
<192.168.1.6> (0, b'ansible-tmp-1632149240.549101-44053-164536349728609=/Users/yuanyi/.ansible/tmp/ansible-tmp-1632149240.549101-44053-164536349728609\n', b'OpenSSH_8.1p1, LibreSSL 2.7.3\r\ndebug1: Reading configuration data /Users/yuanyi/.ssh/config\r\ndebug1: /Users/yuanyi/.ssh/config line 1: Applying options for *\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 47: Applying options for *\r\ndebug2: resolve_canonicalize: hostname 192.168.1.6 is address\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 43920\r\ndebug3: mux_client_request_session: session request sent\r\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 0\r\n')
Using module file /Users/yuanyi/.ansible/collections/ansible_collections/community/docker/plugins/modules/docker_container.py
<192.168.1.6> PUT /Users/yuanyi/.ansible/tmp/ansible-local-44002xglshlp4/tmp77i38cto TO /Users/yuanyi/.ansible/tmp/ansible-tmp-1632149240.549101-44053-164536349728609/AnsiballZ_docker_container.py
<192.168.1.6> SSH: EXEC sftp -b - -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/Users/yuanyi/.ansible/cp/c3dbd47e8c '[192.168.1.6]'
<192.168.1.6> (0, b'sftp> put /Users/yuanyi/.ansible/tmp/ansible-local-44002xglshlp4/tmp77i38cto /Users/yuanyi/.ansible/tmp/ansible-tmp-1632149240.549101-44053-164536349728609/AnsiballZ_docker_container.py\n', b'OpenSSH_8.1p1, LibreSSL 2.7.3\r\ndebug1: Reading configuration data /Users/yuanyi/.ssh/config\r\ndebug1: /Users/yuanyi/.ssh/config line 1: Applying options for *\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 47: Applying options for *\r\ndebug2: resolve_canonicalize: hostname 192.168.1.6 is address\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 43920\r\ndebug3: mux_client_request_session: session request sent\r\ndebug2: Remote version: 3\r\ndebug2: Server supports extension "posix-rename@openssh.com" revision 1\r\ndebug2: Server supports extension "statvfs@openssh.com" revision 2\r\ndebug2: Server supports extension "fstatvfs@openssh.com" revision 2\r\ndebug2: Server supports extension "hardlink@openssh.com" revision 1\r\ndebug2: Server supports extension "fsync@openssh.com" revision 1\r\ndebug2: Server supports extension "lsetstat@openssh.com" revision 1\r\ndebug3: Sent message fd 3 T:16 I:1\r\ndebug3: SSH_FXP_REALPATH . -> /Users/yuanyi size 0\r\ndebug3: Looking up /Users/yuanyi/.ansible/tmp/ansible-local-44002xglshlp4/tmp77i38cto\r\ndebug3: Sent message fd 3 T:17 I:2\r\ndebug3: Received stat reply T:101 I:2\r\ndebug1: Couldn\'t stat remote file: No such file or directory\r\ndebug3: Sent message SSH2_FXP_OPEN I:3 P:/Users/yuanyi/.ansible/tmp/ansible-tmp-1632149240.549101-44053-164536349728609/AnsiballZ_docker_container.py\r\ndebug3: Sent message SSH2_FXP_WRITE I:4 O:0 S:32768\r\ndebug3: SSH2_FXP_STATUS 0\r\ndebug3: In write loop, ack for 4 32768 bytes at 0\r\ndebug3: Sent message SSH2_FXP_WRITE I:5 O:32768 S:32768\r\ndebug3: Sent message SSH2_FXP_WRITE I:6 O:65536 S:32768\r\ndebug3: Sent message SSH2_FXP_WRITE I:7 O:98304 S:32768\r\ndebug3: Sent message SSH2_FXP_WRITE I:8 O:131072 S:32768\r\ndebug3: Sent message SSH2_FXP_WRITE I:9 O:163840 S:11853\r\ndebug3: SSH2_FXP_STATUS 0\r\ndebug3: In write loop, ack for 5 32768 bytes at 32768\r\ndebug3: SSH2_FXP_STATUS 0\r\ndebug3: In write loop, ack for 6 32768 bytes at 65536\r\ndebug3: SSH2_FXP_STATUS 0\r\ndebug3: In write loop, ack for 7 32768 bytes at 98304\r\ndebug3: SSH2_FXP_STATUS 0\r\ndebug3: In write loop, ack for 8 32768 bytes at 131072\r\ndebug3: SSH2_FXP_STATUS 0\r\ndebug3: In write loop, ack for 9 11853 bytes at 163840\r\ndebug3: Sent message SSH2_FXP_CLOSE I:4\r\ndebug3: SSH2_FXP_STATUS 0\r\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 0\r\n')
<192.168.1.6> ESTABLISH SSH CONNECTION FOR USER: None
<192.168.1.6> SSH: EXEC ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/Users/yuanyi/.ansible/cp/c3dbd47e8c 192.168.1.6 '/bin/sh -c '"'"'chmod u+x /Users/yuanyi/.ansible/tmp/ansible-tmp-1632149240.549101-44053-164536349728609/ /Users/yuanyi/.ansible/tmp/ansible-tmp-1632149240.549101-44053-164536349728609/AnsiballZ_docker_container.py && sleep 0'"'"''
<192.168.1.6> (0, b'', b'OpenSSH_8.1p1, LibreSSL 2.7.3\r\ndebug1: Reading configuration data /Users/yuanyi/.ssh/config\r\ndebug1: /Users/yuanyi/.ssh/config line 1: Applying options for *\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 47: Applying options for *\r\ndebug2: resolve_canonicalize: hostname 192.168.1.6 is address\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 43920\r\ndebug3: mux_client_request_session: session request sent\r\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 0\r\n')
<192.168.1.6> ESTABLISH SSH CONNECTION FOR USER: None
<192.168.1.6> SSH: EXEC ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/Users/yuanyi/.ansible/cp/c3dbd47e8c -tt 192.168.1.6 '/bin/sh -c '"'"'/usr/bin/python /Users/yuanyi/.ansible/tmp/ansible-tmp-1632149240.549101-44053-164536349728609/AnsiballZ_docker_container.py && sleep 0'"'"''
<192.168.1.6> (1, b'\r\n{"msg": "Failed to import the required Python library (Docker SDK for Python: docker above 5.0.0 (Python >= 3.6) or docker before 5.0.0 (Python 2.7) or docker-py (Python 2.6)) on 192.168.1.6\'s Python /System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python. Please read the module documentation and install it in the appropriate location. If the required library is installed, but Ansible is using the wrong Python interpreter, please consult the documentation on ansible_python_interpreter, for example via `pip install docker` (Python >= 3.6) or `pip install docker==4.4.4` (Python 2.7) or `pip install docker-py` (Python 2.6). The error was: No module named requests.exceptions", "failed": true, "exception": "Traceback (most recent call last):\\n  File \\"/var/folders/gc/1zj1qyzj5sl03hvzmccb_bs00000gn/T/ansible_community.docker.docker_container_payload_zEDNdl/ansible_community.docker.docker_container_payload.zip/ansible_collections/community/docker/plugins/module_utils/common.py\\", line 32, in <module>\\n    from requests.exceptions import SSLError\\nImportError: No module named requests.exceptions\\n", "invocation": {"module_args": {"tty": null, "dns_servers": null, "labels": null, "docker_host": "unix://var/run/docker.sock", "cpuset_cpus": null, "storage_opts": null, "force_kill": false, "networks": null, "detach": null, "device_read_bps": null, "use_ssh_client": false, "capabilities": null, "init": null, "volumes_from": null, "log_options": null, "device_requests": null, "device_write_iops": null, "network_mode": null, "tmpfs": null, "restart": false, "name": "observer", "privileged": null, "default_host_ip": null, "timeout": 60, "debug": false, "validate_certs": false, "ulimits": null, "cpu_shares": null, "dns_search_domains": null, "env_file": null, "cpu_quota": null, "cpuset_mems": null, "mac_address": null, "state": "started", "oom_killer": null, "blkio_weight": null, "api_version": "auto", "exposed_ports": null, "shm_size": null, "mounts": null, "container_default_behavior": null, "restart_retries": null, "groups": null, "tls": false, "tls_hostname": null, "ignore_image": false, "volume_driver": null, "sysctls": null, "ipc_mode": null, "runtime": null, "publish_all_ports": null, "keep_volumes": true, "image": "ghcr.io/hyperledger-twgc/tape:edge", "recreate": false, "cpus": null, "pid_mode": null, "cpu_period": null, "domainname": null, "memory": null, "auto_remove": null, "memory_swappiness": null, "memory_swap": null, "pull": false, "stop_signal": null, "devices": null, "uts": null, "networks_cli_compatible": true, "published_ports": null, "cap_drop": null, "interactive": null, "removal_wait_timeout": null, "links": null, "oom_score_adj": null, "restart_policy": null, "command": "tape version", "paused": null, "stop_timeout": null, "security_opts": null, "client_key": null, "read_only": null, "hostname": null, "dns_opts": null, "working_dir": null, "cleanup": false, "entrypoint": null, "env": null, "pids_limit": null, "client_cert": null, "log_driver": null, "ca_cert": null, "healthcheck": null, "cgroup_parent": null, "kill_signal": null, "user": null, "userns_mode": null, "purge_networks": false, "output_logs": false, "device_read_iops": null, "ssl_version": null, "kernel_memory": null, "etc_hosts": null, "memory_reservation": null, "command_handling": null, "volumes": null, "comparisons": null, "device_write_bps": null}}}\r\n', b'OpenSSH_8.1p1, LibreSSL 2.7.3\r\ndebug1: Reading configuration data /Users/yuanyi/.ssh/config\r\ndebug1: /Users/yuanyi/.ssh/config line 1: Applying options for *\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 47: Applying options for *\r\ndebug2: resolve_canonicalize: hostname 192.168.1.6 is address\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 43920\r\ndebug3: mux_client_request_session: session request sent\r\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 1\r\nShared connection to 192.168.1.6 closed.\r\n')
<192.168.1.6> Failed to connect to the host via ssh: OpenSSH_8.1p1, LibreSSL 2.7.3
debug1: Reading configuration data /Users/yuanyi/.ssh/config
debug1: /Users/yuanyi/.ssh/config line 1: Applying options for *
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 47: Applying options for *
debug2: resolve_canonicalize: hostname 192.168.1.6 is address
debug1: auto-mux: Trying existing master
debug2: fd 3 setting O_NONBLOCK
debug2: mux_client_hello_exchange: master version 4
debug3: mux_client_forwards: request forwardings: 0 local, 0 remote
debug3: mux_client_request_session: entering
debug3: mux_client_request_alive: entering
debug3: mux_client_request_alive: done pid = 43920
debug3: mux_client_request_session: session request sent
debug3: mux_client_read_packet: read header failed: Broken pipe
debug2: Received exit status from master 1
Shared connection to 192.168.1.6 closed.
<192.168.1.6> ESTABLISH SSH CONNECTION FOR USER: None
<192.168.1.6> SSH: EXEC ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/Users/yuanyi/.ansible/cp/c3dbd47e8c 192.168.1.6 '/bin/sh -c '"'"'rm -f -r /Users/yuanyi/.ansible/tmp/ansible-tmp-1632149240.549101-44053-164536349728609/ > /dev/null 2>&1 && sleep 0'"'"''
<192.168.1.6> (0, b'', b'OpenSSH_8.1p1, LibreSSL 2.7.3\r\ndebug1: Reading configuration data /Users/yuanyi/.ssh/config\r\ndebug1: /Users/yuanyi/.ssh/config line 1: Applying options for *\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 47: Applying options for *\r\ndebug2: resolve_canonicalize: hostname 192.168.1.6 is address\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 43920\r\ndebug3: mux_client_request_session: session request sent\r\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 0\r\n')
The full traceback is:
Traceback (most recent call last):
  File "/var/folders/gc/1zj1qyzj5sl03hvzmccb_bs00000gn/T/ansible_community.docker.docker_container_payload_zEDNdl/ansible_community.docker.docker_container_payload.zip/ansible_collections/community/docker/plugins/module_utils/common.py", line 32, in <module>
    from requests.exceptions import SSLError
ImportError: No module named requests.exceptions
fatal: [192.168.1.6]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "api_version": "auto",
            "auto_remove": null,
            "blkio_weight": null,
            "ca_cert": null,
            "cap_drop": null,
            "capabilities": null,
            "cgroup_parent": null,
            "cleanup": false,
            "client_cert": null,
            "client_key": null,
            "command": "tape version",
            "command_handling": null,
            "comparisons": null,
            "container_default_behavior": null,
            "cpu_period": null,
            "cpu_quota": null,
            "cpu_shares": null,
            "cpus": null,
            "cpuset_cpus": null,
            "cpuset_mems": null,
            "debug": false,
            "default_host_ip": null,
            "detach": null,
            "device_read_bps": null,
            "device_read_iops": null,
            "device_requests": null,
            "device_write_bps": null,
            "device_write_iops": null,
            "devices": null,
            "dns_opts": null,
            "dns_search_domains": null,
            "dns_servers": null,
            "docker_host": "unix://var/run/docker.sock",
            "domainname": null,
            "entrypoint": null,
            "env": null,
            "env_file": null,
            "etc_hosts": null,
            "exposed_ports": null,
            "force_kill": false,
            "groups": null,
            "healthcheck": null,
            "hostname": null,
            "ignore_image": false,
            "image": "ghcr.io/hyperledger-twgc/tape:edge",
            "init": null,
            "interactive": null,
            "ipc_mode": null,
            "keep_volumes": true,
            "kernel_memory": null,
            "kill_signal": null,
            "labels": null,
            "links": null,
            "log_driver": null,
            "log_options": null,
            "mac_address": null,
            "memory": null,
            "memory_reservation": null,
            "memory_swap": null,
            "memory_swappiness": null,
            "mounts": null,
            "name": "observer",
            "network_mode": null,
            "networks": null,
            "networks_cli_compatible": true,
            "oom_killer": null,
            "oom_score_adj": null,
            "output_logs": false,
            "paused": null,
            "pid_mode": null,
            "pids_limit": null,
            "privileged": null,
            "publish_all_ports": null,
            "published_ports": null,
            "pull": false,
            "purge_networks": false,
            "read_only": null,
            "recreate": false,
            "removal_wait_timeout": null,
            "restart": false,
            "restart_policy": null,
            "restart_retries": null,
            "runtime": null,
            "security_opts": null,
            "shm_size": null,
            "ssl_version": null,
            "state": "started",
            "stop_signal": null,
            "stop_timeout": null,
            "storage_opts": null,
            "sysctls": null,
            "timeout": 60,
            "tls": false,
            "tls_hostname": null,
            "tmpfs": null,
            "tty": null,
            "ulimits": null,
            "use_ssh_client": false,
            "user": null,
            "userns_mode": null,
            "uts": null,
            "validate_certs": false,
            "volume_driver": null,
            "volumes": null,
            "volumes_from": null,
            "working_dir": null
        }
    },
    "msg": "Failed to import the required Python library (Docker SDK for Python: docker above 5.0.0 (Python >= 3.6) or docker before 5.0.0 (Python 2.7) or docker-py (Python 2.6)) on 192.168.1.6's Python /System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python. Please read the module documentation and install it in the appropriate location. If the required library is installed, but Ansible is using the wrong Python interpreter, please consult the documentation on ansible_python_interpreter, for example via `pip install docker` (Python >= 3.6) or `pip install docker==4.4.4` (Python 2.7) or `pip install docker-py` (Python 2.6). The error was: No module named requests.exceptions"
}
felixfontein commented 3 years ago

Did you install the Docker SDK for Python for the same Python that Ansible uses on your target? I.e. for the Python in /System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python on 192.168.1.6?

felixfontein commented 3 years ago

@SamYuan1990 can you please answer this question?

SamYuan1990 commented 3 years ago

Did you install the Docker SDK for Python for the same Python that Ansible uses on your target? I.e. for the Python in /System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python on 192.168.1.6?

sorry for reply late, yes I installed docker sdk for python as hint, and retried many times. but I am not sure if the problem is related to python or $PATH

I tried to print $PATH from ansible and by ssh in console, and the result for $PATH is different. seems that echo $PATH missing some path for libs.

felixfontein commented 3 years ago

I don't think $PATH is related to this. You seem to have installed Ansible with Python 3.9.1, but Ansible uses Python 2.7 on your machine. So you need to either install Docker SDK for Python for the Python 2.7 on your machine, or you need to tell Ansible to use Python 3.9.1 and not Python 2.7. For the latter, you can use the ansible_python_interpreter inventory (or local) variable.

Example:

- hosts: localhost
  vars:
    ansible_python_interpreter: /path/to/python3.9
  tasks:
    ...
SamYuan1990 commented 3 years ago

but for distributes considering, is it good idea to had code as:

  vars:
    ansible_python_interpreter: /path/to/python3.9
/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python

is only for local mac right? if I use mac for dev, and others use for linux?

felixfontein commented 3 years ago

It's definitely not. But it shows that in this case, you simply installed the Docker SDK for Python for the wrong Python version on your local machine. If you install it for the correct one, you don't need this hack.

In any case, this is not a bug in the collection, but a usage problem. These can be discussed in the ansible-project mailing list or in #ansible in IRC. I'll close this issue because of that.