Daniel Ashton
Daniel Ashton

Reputation: 1438

How to get Ansible on Fedora 30 to see modules

I installed Ansible 2.8.2 using dnf on Fedora 30. I have an Ansible plug-in that requires a library. Using pip3 install I installed the required library.

When I run ansible-playbook directly, I see a ModuleNotFoundError for that module.

But if I run python3 /usr/bin/ansible-playbook, the module is found.

How can I get Ansible as installed by dnf to see this library?

Edit: further info: as installed from dnf, the main Ansible script has a shebang for /usr/bin/python3 -s. If I remove the -s, this problem is solved.

  1. What's the benefit that the repo maintainers were seeking in adding this -s flag?

  2. Is there a case to be made for asking the repo maintainers to omit the flag?

  3. How can I get pip3 to install the library I need into a directory that will be seen when the -s flag is in effect?

Edit: Here's the output of ansible --version, and thanks for asking.

ansible 2.8.2
  config file = /home/jdashton/proj/ansible-ccharacter/ansible.cfg
  configured module search path = ['/home/jdashton/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.7.4 (default, Jul  9 2019, 16:32:37) [GCC 9.1.1 20190503 (Red Hat 9.1.1-1)]

This is different from the suggested duplicate question because that question describes a "remote" task being run on localhost, in which case Ansible uses the default "remote" python interpreter. In this question, the library is being called from a local plugin, under Ansible's own python process. The -s flag in the shebang line at the top of the /usr/bin/ansible script is preventing Ansible from seeing some local libraries.

Edit: Following the suggestion from @zigarn I tried removing the library and reinstalling it as root. This resulted in the library being reinstalled into the same directory /usr/local/lib/... as before. Is there a way to get pip3 to install into the system library?

Here are the commands I attempted:

# pip3 uninstall tenacity
Uninstalling tenacity-5.0.4:
  Would remove:
    /usr/local/lib/python3.7/site-packages/tenacity-5.0.4.dist-info/*
    /usr/local/lib/python3.7/site-packages/tenacity/*
Proceed (y/n)? y
  Successfully uninstalled tenacity-5.0.4
# pip3 install tenacity
Collecting tenacity
  Using cached https://files.pythonhosted.org/packages/6a/93/dfcf5b1b46ab29196274b78dcba69fab5e54b6dc303a7eed90a79194d277/tenacity-5.0.4-py2.py3-none-any.whl
Requirement already satisfied: six>=1.9.0 in /usr/lib/python3.7/site-packages (from tenacity) (1.12.0)
Installing collected packages: tenacity
Successfully installed tenacity-5.0.4
# pip show tenacity
Name: tenacity
Version: 5.0.4
Summary: Retry code until it succeeeds
Home-page: https://github.com/jd/tenacity
Author: Julien Danjou
Author-email: [email protected]
License: Apache 2.0
Location: /usr/local/lib/python3.7/site-packages
Requires: six
Required-by: 

Also, for clarity, here is the source for the Ansible installation:

# dnf list ansible
Last metadata expiration check: 0:09:48 ago on Mon 12 Aug 2019 11:12:58 AM EDT.
Installed Packages
ansible.noarch                                               2.8.2-1.fc30                                               @updates

Upvotes: 0

Views: 390

Answers (1)

zigarn
zigarn

Reputation: 11625

According to the documentation -s option of python is "Don’t add the user site-packages directory to sys.path."

So I would guess that you did pip3 install as your user instead as root, so the library was installed at your user side instead of system wide.

Try to reinstall the library with pip3 as root and it should be ok.

Upvotes: 1

Related Questions