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

What do "present in the Mitogen importer blacklist" errors mean? #724

Open
lonix1 opened this issue Jun 12, 2020 · 8 comments
Open

What do "present in the Mitogen importer blacklist" errors mean? #724

lonix1 opened this issue Jun 12, 2020 · 8 comments

Comments

@lonix1
Copy link

lonix1 commented Jun 12, 2020

ubuntu 20.04
ansible 2.9.6
python 3.8.2
mitogen beta 0.2.10 2020-05-16 (also tried 0.2.9)

I often get similar error to the one below. They generally say something like

The error was: 'FOO' is present in the Mitogen importer blacklist, therefore this context will not attempt to request it from the master, as the request will always be refused.

In this particular case, I'm checking something on localhost:

- docker_swarm_info:
  ignore_errors: yes
  register: result

Error:

fatal: [localhost]: FAILED! => {"can_talk_to_docker": false, "changed": false, "docker_swarm_active": false, "docker_swarm_manager": false, "msg": "Failed to import the required Python library (Docker SDK for Python: docker (Python >= 2.7) or docker-py (Python 2.6)) on lonix1's Python /usr/bin/python3. 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: 'docker' is present in the Mitogen importer blacklist, therefore this context will not attempt to request it from the master, as the request will always be refused."}

It works when mitogen isn't enabled.

@s1113950
Copy link
Collaborator

This part is the most important: on lonix1's Python /usr/bin/python3.

Mitogen works by streaming package data to its clients, so if the package doesn't exist on your host machine (the "master") then it doesn't make sense for the target node to request it from the master because it doesn't exist there.

Mitogen is designed to require minimal installation of packages to get stuff to work on target hosts :) Please try installing docker on your host via /usr/bin/python3 -m pip install docker and rerunning. This is the python that Mitogen detected it should use which might be different than what Ansible defaults to (although it shouldn't; I call the same code from Ansible that it uses to detect python versions 🤔 ). At first guess, it might be due to a symlink pointing to a different Python.
If that doesn't work I can take a closer look! It'll also help if you can reproduce the issue with a minimal Dockerfile in that case.

@lonix1
Copy link
Author

lonix1 commented Jun 13, 2020

Thanks.

I'm not a python dev so it'll take a while to dig into your recommendations.

In the meantime, I looked into the symlink theory. This is what I found:

Master's ansible.cfg:

[defaults]
interpreter_python = /usr/bin/python3
strategy_plugins = ~/.mitogen/ansible_mitogen/plugins/strategy
strategy = mitogen_linear

Master:

$ which python; which python2; which python3
/usr/bin/python
/usr/bin/python2
/usr/bin/python3

$ python --version; python2 --version; python3 --version
Python 2.7.18rc1
Python 2.7.18rc1
Python 3.8.2

Remote:

$ which python; which python2; which python3
/usr/bin/python
/usr/bin/python2
/usr/bin/python3

$ python --version; python2 --version; python3 --version
Python 2.7.17
Python 2.7.17
Python 3.6.9

Looks ok?

@s1113950
Copy link
Collaborator

Sorry for the late response; I thought I responded to this already :(
The symlink stuff looks ok. Does this show docker on your host?

$ /usr/bin/python3 -m pip freeze | grep docker

@JiffsMaverick
Copy link

JiffsMaverick commented Jul 21, 2021

@s1113950 I have same problem. My playbook for reproducing:

- hosts: all
  become: true
  tasks:
    - name: step1
      ansible.builtin.pip:
        name: docker
        executable: pip3

    - name: step2
      community.docker.docker_host_info:

Error:

fatal: [myhost.com]: FAILED! => {"ansible_facts": {"discovered_interpreter_python": "/bin/python3.6"}, "can_talk_to_docker": false, "changed": false, "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 myhost.com's Python /bin/python3.6. 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: 'docker' is present in the Mitogen importer blacklist, therefore this context will not attempt to request it from the master, as the request will always be refused."}

Important moment: playbook is restarted without errors.

But, I found workaround. It need to reset connection between step 1 and step2. Like this:

- hosts: all
  become: true
  tasks:
    - name: step1
      ansible.builtin.pip:
        name: docker
        executable: /bin/pip3.6

    - name: reset ssh connection
      ansible.builtin.meta: reset_connection

    - name: step2
      community.docker.docker_host_info:

Info about my system:
OS: Oracle Linux Server 8.4
Ansible: 2.10.11
mitogen: 0.3.0-rc1

Python:

[root@myhost.com ~]# /bin/python3.6 --version
Python 3.6.8

Docker package:

[root@myhost.com ~]# /bin/pip3.6 list | grep docker
docker (5.0.0)

@pkit
Copy link

pkit commented Mar 25, 2022

Sorry for the late response; I thought I responded to this already :( The symlink stuff looks ok. Does this show docker on your host?

$ /usr/bin/python3 -m pip freeze | grep docker

Docker is installed

$ /usr/bin/python3 -m pip freeze | grep docker
docker==5.0.3

Still mitogen fails with

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 ec3fa6e91296''s Python /usr/bin/python3. 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: ''docker'' is present in the Mitogen importer blacklist, therefore this context will not attempt to request it from the master, as the request will always be refused.'
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ModuleNotFoundError: 'docker' is present in the Mitogen importer blacklist, therefore this context will not attempt to request it from the master, as the request will always be refused.

Obviously imports just fine in the REPL.

  ansible_facts:
    discovered_interpreter_python: /usr/bin/python3

@jdelStrother
Copy link

FWIW I was also seeing a similar error when running a task like:

  community.general.docker_container:
    name: sphinx
    image: macbre/sphinxsearch:3.4.1
    state: started
    restart_policy: unless-stopped
    container_default_behavior: no_defaults
    user: "{{ getent_passwd['sphinx'].1 }}:{{ getent_passwd['sphinx'].2 }}"

resulting in:

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ModuleNotFoundError: 'docker' is present in the Mitogen importer blacklist, therefore this context will not attempt to request it from the master, as the request will always be refused.
fatal: [development-server1-1]: FAILED! => {"changed": false, "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 development-server1-1's Python /usr/bin/python3. 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: 'docker' is present in the Mitogen importer blacklist, therefore this context will not attempt to request it from the master, as the request will always be refused."}

However! If I change my playbook strategy back to linear to bypass mitogen entirely, it still fails:

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ModuleNotFoundError: No module named 'docker'
fatal: [development-server1-1]: FAILED! => {"changed": false, "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 development-server1-1's Python /usr/bin/python3. 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 'docker'"}

So (at least in my case) the "Mitogen importer blacklist" error message was misleading (my actual problem was that I'd run pip3 install docker as a user account, then tried to run community.general.docker_container as root).

@dberardo-com
Copy link

in my case i get a similar error but using the linear strategy makes the problem go away ...

any hint why this is not working ?

@Ray-Sir-Like
Copy link

Sorry for the late response; I thought I responded to this already :( The symlink stuff looks ok. Does this show docker on your host?

$ /usr/bin/python3 -m pip freeze | grep docker

Docker is installed

$ /usr/bin/python3 -m pip freeze | grep docker
docker==5.0.3

Still mitogen fails with

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 ec3fa6e91296''s Python /usr/bin/python3. 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: ''docker'' is present in the Mitogen importer blacklist, therefore this context will not attempt to request it from the master, as the request will always be refused.'
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ModuleNotFoundError: 'docker' is present in the Mitogen importer blacklist, therefore this context will not attempt to request it from the master, as the request will always be refused.

Obviously imports just fine in the REPL.

  ansible_facts:
    discovered_interpreter_python: /usr/bin/python3

How did you end up solving this problem?

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

No branches or pull requests

7 participants