Skip to content
This repository has been archived by the owner on Jun 13, 2024. It is now read-only.

CI failing with "cannot import name 'AnsibleCollectionLoader'" #135

Closed
geerlingguy opened this issue Jun 18, 2020 · 16 comments
Closed

CI failing with "cannot import name 'AnsibleCollectionLoader'" #135

geerlingguy opened this issue Jun 18, 2020 · 16 comments

Comments

@geerlingguy
Copy link
Collaborator

geerlingguy commented Jun 18, 2020

SUMMARY

CI testing has started failing today with the error message down below.

See failed build: https://github.com/ansible-collections/community.kubernetes/runs/785830751?check_suite_focus=true#step:8:21

ISSUE TYPE
  • Bug Report
COMPONENT NAME

CI / Molecule

ANSIBLE VERSION

TODO.

CONFIGURATION

TODO.

OS / ENVIRONMENT

GitHub Actions

STEPS TO REPRODUCE

Run GitHub Actions workflow, molecule test:

molecule test
EXPECTED RESULTS

Tests pass.

ACTUAL RESULTS

Molecule tests fail:

--> Action: 'syntax'
ERROR! Unexpected Exception, this is probably a bug: cannot import name 'AnsibleCollectionLoader' from 'ansible.utils.collection_loader' (/opt/hostedtoolcache/Python/3.7.7/x64/lib/python3.7/site-packages/ansible/utils/collection_loader/__init__.py)
    the full traceback was:
    
    Traceback (most recent call last):
      File "/opt/hostedtoolcache/Python/3.7.7/x64/bin/ansible-playbook", line 92, in <module>
        mycli = getattr(__import__("ansible.cli.%s" % sub, fromlist=[myclass]), myclass)
      File "/opt/hostedtoolcache/Python/3.7.7/x64/lib/python3.7/site-packages/ansible/cli/__init__.py", line 22, in <module>
        from ansible.inventory.manager import InventoryManager
      File "/opt/hostedtoolcache/Python/3.7.7/x64/lib/python3.7/site-packages/ansible/inventory/manager.py", line 38, in <module>
        from ansible.plugins.loader import inventory_loader
      File "/opt/hostedtoolcache/Python/3.7.7/x64/lib/python3.7/site-packages/ansible/plugins/loader.py", line 26, in <module>
        from ansible.utils.collection_loader import AnsibleCollectionLoader, AnsibleFlatMapLoader, AnsibleCollectionRef
    ImportError: cannot import name 'AnsibleCollectionLoader' from 'ansible.utils.collection_loader' (/opt/hostedtoolcache/Python/3.7.7/x64/lib/python3.7/site-packages/ansible/utils/collection_loader/__init__.py)
ERROR: 
An error occurred during the test sequence action: 'syntax'. Cleaning up.
@geerlingguy
Copy link
Collaborator Author

Testing locally with Ansible 2.9.9 there's no issue.

@geerlingguy
Copy link
Collaborator Author

I also tested with 2.11.0.dev0 and didn't have an issue:

$ ansible --version
[WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are
modifying the Ansible engine, or trying out features under development. This is a rapidly changing source of code and
can become unstable at any point.
ansible 2.11.0.dev0

@geerlingguy
Copy link
Collaborator Author

Tried with 2.9.10 and the current 2.10.0 devel too, no problems locally. ???

@geerlingguy
Copy link
Collaborator Author

And... now I can't get the problem to reproduce on GitHub Actions, so I guess it was some weird transient issue.

Closing this.

@jamesmarshall24
Copy link

@geerlingguy I ran into the same today randomly and had to uninstall Ansible and delete the ansible directory under site-packages. After reinstalling Ansible, I could no longer replicate the error.

@NicoWde
Copy link

NicoWde commented Jul 7, 2020

@jamesmarshall24 @geerlingguy I recently ran into it..

think the problem is somehow somewhere between the package-names 'ansible' and 'ansible-base' (in my case: installed via pip)

@geerlingguy
Copy link
Collaborator Author

Grr, I just ran into this again locally, after I was installing Ansible 2.9.10, then 2.10 pre, then ansible-base, then Ansible 2.9.10 again.

The fix was as @jamesmarshall24 and @NicoWde stated:

  1. pip3 uninstall ansible
  2. rm -rf /usr/local/lib/python3.7/site-packages/ansible (things that weren't automatically removed)
  3. pip3 install ansible

srl295 added a commit to srl295/cldr that referenced this issue Sep 23, 2020
lerwys added a commit to lnls-sirius/lnls-ansible that referenced this issue Sep 23, 2020
srl295 added a commit to unicode-org/cldr that referenced this issue Sep 23, 2020
pedberg-icu pushed a commit to unicode-org/cldr that referenced this issue Sep 24, 2020
- see ansible-collections/community.kubernetes#135 (comment)
- workaround by not setting a version

(cherry picked from commit 1fb7d3b)
arshdeeptinna added a commit to arshdeeptinna/ansible_helpers that referenced this issue Sep 25, 2020
There is some issue introduced with ansible 2.10
ansible-collections/community.kubernetes#135
@distributorofpain
Copy link

Grr, I just ran into this again locally, after I was installing Ansible 2.9.10, then 2.10 pre, then ansible-base, then Ansible 2.9.10 again.

The fix was as @jamesmarshall24 and @NicoWde stated:

  1. pip3 uninstall ansible
  2. rm -rf /usr/local/lib/python3.7/site-packages/ansible (things that weren't automatically removed)
  3. pip3 install ansible

Note, on CentOS 8, i had to change the python path to 3.6 to remove the right directory. But it fixed my issue.

@tzvifriedman
Copy link

Just a note on the above, aside from also changing the python version, in Ubuntu 18.04, it's dist-packages and not site-packages. Took me some time to figure that one out.

@strarsis
Copy link

Yes, had to uninstall ansible-base package, too, not just the ansible package: pip3 uninstall ansible-base.
pip3 list can help finding extraneous packages.
Also note that root user and normal user can easily have different pip packages and therefore ansible versions.
ansible-base was installed on normal user and on root user, adding extra confusion and errors when trying to use ansible.

sudo apt autoremove ansible
sudo pip3 uninstall ansible
sudo pip3 uninstall ansible-base
pip3 uninstall ansible
pip3 uninstall ansible-base

@SturmB
Copy link

SturmB commented Oct 16, 2020

I just now learned about GitHub Actions and decided to give it a try. My first action is using ansible-lint. And I now get this error message every time I push. However, ansible-lint runs fine locally and I've already corrected all issues it brought up.

Is there something I need to do to correct this, or is it something that's buggy with GitHub's Actions?

@shinebayar-g
Copy link

Grr, I just ran into this again locally, after I was installing Ansible 2.9.10, then 2.10 pre, then ansible-base, then Ansible 2.9.10 again.

The fix was as @jamesmarshall24 and @NicoWde stated:

  1. pip3 uninstall ansible
  2. rm -rf /usr/local/lib/python3.7/site-packages/ansible (things that weren't automatically removed)
  3. pip3 install ansible

This really helped. Thank you!
I guess pip uninstall ansible doesn't really clean everything.

@ader1990
Copy link

ader1990 commented Jan 4, 2021

Yes, had to uninstall ansible-base package, too, not just the ansible package: pip3 uninstall ansible-base.
pip3 list can help finding extraneous packages.
Also note that root user and normal user can easily have different pip packages and therefore ansible versions.
ansible-base was installed on normal user and on root user, adding extra confusion and errors when trying to use ansible.

sudo apt autoremove ansible
sudo pip3 uninstall ansible
sudo pip3 uninstall ansible-base
pip3 uninstall ansible
pip3 uninstall ansible-base

this is the correct solution.

@wolfwolker
Copy link

same problem here in ubuntu 20.04, reinstalling with pip3 worked for me :)
thanks a lot

@iamgini
Copy link

iamgini commented Mar 23, 2021

Grr, I just ran into this again locally, after I was installing Ansible 2.9.10, then 2.10 pre, then ansible-base, then Ansible 2.9.10 again.

The fix was as @jamesmarshall24 and @NicoWde stated:

  1. pip3 uninstall ansible
  2. rm -rf /usr/local/lib/python3.7/site-packages/ansible (things that weren't automatically removed)
  3. pip3 install ansible

Perfect. It worked.

lucky, I was using it inside venv !

thank you @geerlingguy

@sanzenwin
Copy link

Grr, I just ran into this again locally, after I was installing Ansible 2.9.10, then 2.10 pre, then ansible-base, then Ansible 2.9.10 again.

The fix was as @jamesmarshall24 and @NicoWde stated:

  1. pip3 uninstall ansible
  2. rm -rf /usr/local/lib/python3.7/site-packages/ansible (things that weren't automatically removed)
  3. pip3 install ansible

Good job !

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests