Ansible-Playbook error against remote Host

  ansible, docker, python

Attempting to run ansible-playbook against remote host using the following syntax:

ansible-playbook --ask-pass --ask-become-pass {application}_test_playbook.yml -i inventory -l dev

and getting the following error:

TASK [Log into private registry] **********************************************************************************************************************************************************************
fatal: [server_name]: FAILED! => {"changed": false, "msg": "Failed to import the required Python library (Docker SDK for Python: docker (Python >= 2.7) or docker-py (Python 2.6)) on {server_name}'s Python /usr/bin/python. Please read module documentation and install 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` or `pip install docker-py` (Python 2.6). The error was: No module named selectors"}

PLAY RECAP ********************************************************************************************************************************************************************************************
{server_name}              : ok=13   changed=3    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0

The inventory file contains the following for the [dev] section:

{server_name} ansible_host={IP_address}

I’ve tried to re-install Python using the commands in the error, but still get the same error.

Source: Docker Questions

One Reply to “Ansible-Playbook error against remote Host”

  • Hey,
    if you try to use docker module, you’ll notice that its using the “websocket” module, which in turn is using the “selectors” module.

    [[email protected] ~]# python
    Python 2.7.5 (default, Nov 16 2020, 22:23:17)
    [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux2
    Type “help”, “copyright”, “credits” or “license” for more information.
    >>> import docker
    Traceback (most recent call last):
    File “”, line 1, in
    File “/usr/lib/python2.7/site-packages/docker/”, line 2, in
    from .api import APIClient
    File “/usr/lib/python2.7/site-packages/docker/api/”, line 2, in
    from .client import APIClient
    File “/usr/lib/python2.7/site-packages/docker/api/”, line 8, in
    import websocket
    File “/usr/lib/python2.7/site-packages/websocket/”, line 22, in
    from ._app import WebSocketApp
    File “/usr/lib/python2.7/site-packages/websocket/”, line 25, in
    import selectors
    ImportError: No module named selectors

    Im my case, version 1.1.0 of “websocket-client” was installed. After downgrading it, i was able to use the docker module again,

    [[email protected] ~]# pip install websocket-client==0.57.0
    Collecting websocket-client==0.57.0
    Downloading (200kB)
    100% |████████████████████████████████| 204kB 1.9MB/s
    Requirement already satisfied (use –upgrade to upgrade): six in /usr/lib/python2.7/site-packages (from websocket-client==0.57.0)
    Installing collected packages: websocket-client
    Found existing installation: websocket-client 1.1.0
    Uninstalling websocket-client-1.1.0:
    Successfully uninstalled websocket-client-1.1.0
    Successfully installed websocket-client-0.57.0
    You are using pip version 8.1.2, however version 21.1.3 is available.
    You should consider upgrading via the ‘pip install –upgrade pip’ command.
    [[email protected] ~]#

    [[email protected] ~]# python -mdocker
    /bin/python: No module named docker.__main__; ‘docker’ is a package and cannot be directly executed
    [[email protected] ~]#