RedHatQE/teflo

Unable to install Ansible collections

Closed this issue · 4 comments

After installing teflo, the following ansible packages/versions are installed:

(teflo) [rywillia@t14s ~]$ pip freeze | grep teflo
teflo==1.2.0
(teflo) [rywillia@t14s ~]$ pip freeze | grep ansible
ansible==4.0.0
ansible-base==2.10.9
ansible-core==2.11.0

When trying to use teflo to install Ansible collections or even invoke the ansible-galaxy command directly, I am getting the following exception:

(teflo) [rywillia@t14s ~]$ ansible-galaxy --help
ERROR! Unexpected Exception, this is probably a bug: cannot import name 'CollectionRequirement' from 'ansible.galaxy.collection' (/home/rywillia/teflo/lib64/python3.9/site-packages/ansible/galaxy/collection/__init__.py)
the full traceback was:

Traceback (most recent call last):
  File "/home/rywillia/teflo/bin/ansible-galaxy", line 92, in <module>
    mycli = getattr(__import__("ansible.cli.%s" % sub, fromlist=[myclass]), myclass)
  File "/home/rywillia/teflo/lib64/python3.9/site-packages/ansible/cli/galaxy.py", line 24, in <module>
    from ansible.galaxy.collection import (
ImportError: cannot import name 'CollectionRequirement' from 'ansible.galaxy.collection' (/home/rywillia/teflo/lib64/python3.9/site-packages/ansible/galaxy/collection/__init__.py)

The problem looks to be with the recent release of Ansible 4.0. Before Ansible 4.0, teflo would install only ansible and ansible-base packages. Now with ansible 4.0 being out, ansible, ansible-base and ansible-core get installed. Resulting in the exception above. By removing ansible-base package, everything works as expected.

(t1) [rywillia@t14s ~]$ pip list | grep teflo
teflo               1.2.0
(t1) [rywillia@t14s ~]$ pip list | grep ansible
ansible             4.0.0
ansible-core        2.11.0
(t1) [rywillia@t14s ~]$ ansible-galaxy --help
usage: ansible-galaxy [-h] [--version] [-v] TYPE ...

Perform various Role and Collection related operations.

positional arguments:
  TYPE
    collection   Manage an Ansible Galaxy collection.
    role         Manage an Ansible Galaxy role.

optional arguments:
  --version      show program's version number, config file location, configured module search path, module location, executable location and
                 exit
  -h, --help     show this help message and exit
  -v, --verbose  verbose mode (-vvv for more, -vvvv to enable connection debugging)

Ansible looks to have documented that if using Ansible 4.0, you will need to uninstall ansible-base. [1] Ansible 3 was based on ansible-base package.

[1] https://groups.google.com/g/ansible-devel/c/AeF2En1RGI8

@ryankwilliams Thank you for the detailed explanation. I will test with removal of ansible_base and new ansible 4 install
Currently this is what we set up with install_requires=[ 'ansible&gt;=2.5.0', 'ansible-base != 2.10.6',
For now the workaround as you said would be uninstalling ansible-base

@rujutashinde Your welcome! Sounds great. Yes, I modified setup.py to remove ansible-base/set ansible to a minimum 4.0.0 and I was able to get past this issue.

Jira ticket CCITCARBON-313 has been created for this issue. Url : https://projects.engineering.redhat.com/browse/CCITCARBON-313

Removed dependency on ansible_base package. This change is added to develop