简体   繁体   中英

Import error when running an Ansible Playbook with a Python module

I am trying to run ansible-playbook with these Python modules: https://github.com/dkorn/manageiq-ansible-module/tree/master/library

and I am failing with the following error:

  from manageiq_client.api import ManageIQClient as MiqApi
ImportError: No module named manageiq_client.api

Now, I understand that I simply need to pip install the manageiq_client on the machine I run on but it is something I actually cannot do because I don't have root access to it to install anything. I was told to use this script :

But I am not sure how. Thanks in advance!

That hacking/test-module script is for developing a module but it bypasses some of the ways ansible executes modules. If you just want to run a module / a playbook, don't use this.

So your problem is just installing a module as non-root, and having the python ansible executes pick it up. Options to try:

  • pip install --user
  • run in a virtualenv
  • set PYTHONPATH manually (slightly tricky to be sure you're only adding...)
  • found a tip in the FAQ how to override python interpreter for modules. If you point it to a virtualenv's bin/python , you can have ansible executed "outside" the venv while the module runs "inside" the venv:

     virtualenv /tmp/v # can be anywhere /tmp/v/bin/pip2 install manageiq_client ansible-playbook --extra-vars ansible_python_interpreter=/tmp/v/bin/python2 add_provider.yml 

    (you can also set ansible_python_interpreter in inventory file)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM