cloudscale-ch / ansible-collection-cloudscale

cloudscale.ch Ansible Collection
https://galaxy.ansible.com/cloudscale_ch/cloud
GNU General Public License v3.0
7 stars 3 forks source link

inventory issue: ERROR! Unexpected Exception, this is probably a bug: cannot import name 'API_URL' from 'ansible_collections.cloudscale_ch.cloud.plugins.module_utils.api' #49

Closed mkobel closed 3 years ago

mkobel commented 3 years ago

Output of ansible-inventory --list -i inventory-dynamic-cloudscale.yml -vvv

ansible-inventory 2.10.4
  config file = /home/my-user/git/ansible/ansible.cfg
  configured module search path = ['/home/my-user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.9/site-packages/ansible
  executable location = /usr/bin/ansible-inventory
  python version = 3.9.1 (default, Dec 13 2020, 11:55:53) [GCC 10.2.0]
Using /home/my-user/git/ansible/ansible.cfg as config file
ERROR! Unexpected Exception, this is probably a bug: cannot import name 'API_URL' from 'ansible_collections.cloudscale_ch.cloud.plugins.module_utils.api' (/home/my-user/git/ansible/collections/ansible_collections/cloudscale_ch/cloud/plugins/module_utils/api.py)
the full traceback was:

Traceback (most recent call last):
  File "/usr/bin/ansible-inventory", line 123, in <module>
    exit_code = cli.run()
  File "/usr/lib/python3.9/site-packages/ansible/cli/inventory.py", line 128, in run
    self.loader, self.inventory, self.vm = self._play_prereqs()
  File "/usr/lib/python3.9/site-packages/ansible/cli/__init__.py", line 467, in _play_prereqs
    inventory = InventoryManager(loader=loader, sources=options['inventory'])
  File "/usr/lib/python3.9/site-packages/ansible/inventory/manager.py", line 166, in __init__
    self.parse_sources(cache=True)
  File "/usr/lib/python3.9/site-packages/ansible/inventory/manager.py", line 224, in parse_sources
    parse = self.parse_source(source, cache=cache)
  File "/usr/lib/python3.9/site-packages/ansible/inventory/manager.py", line 275, in parse_source
    for plugin in self._fetch_inventory_plugins():
  File "/usr/lib/python3.9/site-packages/ansible/inventory/manager.py", line 203, in _fetch_inventory_plugins
    plugin = inventory_loader.get(name)
  File "/usr/lib/python3.9/site-packages/ansible/plugins/loader.py", line 780, in get
    return self.get_with_context(name, *args, **kwargs).object
  File "/usr/lib/python3.9/site-packages/ansible/plugins/loader.py", line 800, in get_with_context
    self._module_cache[path] = self._load_module_source(name, path)
  File "/usr/lib/python3.9/site-packages/ansible/plugins/loader.py", line 764, in _load_module_source
    spec.loader.exec_module(module)
  File "<frozen importlib._bootstrap_external>", line 790, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/home/my-user/git/ansible/collections/ansible_collections/cloudscale_ch/cloud/plugins/inventory/inventory.py", line 82, in <module>
    from ..module_utils.api import API_URL
ImportError: cannot import name 'API_URL' from 'ansible_collections.cloudscale_ch.cloud.plugins.module_utils.api' (/home/my-user/git/ansible/collections/ansible_collections/cloudscale_ch/cloud/plugins/module_utils/api.py)

Inventory inventory-dynamic-cloudscale.yml:

plugin: cloudscale_ch.cloud.inventory
api_token: ENTER_API_TOKEN_HERE
keyed_groups:
  - prefix: os
    key: cloudscale.image.operating_system | lower

(Based on https://docs.ansible.com/ansible/2.10/collections/cloudscale_ch/cloud/inventory_inventory.html#examples)

Inventory config from ansible.cfg

[inventory]
enable_plugins = ini, cloudscale_ch.cloud.inventory

Installed configuring requirements.txt and executing ansible-galaxy collection install -r requirements.yml -p collections

collections:
  - name: cloudscale_ch.cloud
    version: 1.3.0

It works for me with the following changes:

Is there something wrong with my setup or is this a bug?

href commented 3 years ago

Thank you for reporting this! This is definitely a fault on our side, a regression from an earlier change to the way parameters were read.

I'm sorry we took so long to get back to you, this flew under our radar. I created a pull request that should fix your issue. It'll have to go through internal QA first, but expect a new release by next week. We have a new feature coming up that will be released at the same time. I'll be sure to give this the appropriate priority internally.