ansible/molecule

Molecule is failing when refreshing Collections cache

MonolithProjects opened this issue · 3 comments

Issue Type

  • Bug report

Molecule and Ansible details

ansible [core 2.12.4]
  config file = None
  configured module search path = ['/home/mike/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/mike/.local/lib/python3.10/site-packages/ansible
  ansible collection location = /home/mike/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/mike/.local/bin/ansible
  python version = 3.10.2 (main, Jan 17 2022, 00:00:00) [GCC 11.2.1 20211203 (Red Hat 11.2.1-7)]
  jinja version = 3.0.3
  libyaml = True
molecule 3.6.1 using python 3.10 
    ansible:2.12.4
    delegated:3.6.1 from molecule
    docker:1.1.0 from molecule_docker requiring collections: community.docker>=1.9.1

Molecule installation method (one of):

  • pip

Ansible installation method (one of):

  • pip

Detail any linters or test runners used:

Running locally on Fedora 35

Desired Behavior

Second molecule command will not fail.

Actual Behaviour

When i run molecule (any command) for Ansible Collection which has more than one dependencies in galaxy.yml for a first time, everything works fine. When i after that re-run molecule (the same or different molecule command), molecule fails when refreshing collections cache.

So basically the molecule is failing when there is no change in the collections cache.

As a workaround for this issue i am forced to manually delete the ansible cache before i run the command. Second options is to temporally comment out the dependencies in galaxy.yml after the cache was created.

This error came with Molecule 3.6.1. Older versions works fine.

Example

❯ git clone git@github.com:lablabs/ansible-collection-wireguard.git
Cloning into 'ansible-collection-wireguard'...
Warning: Permanently added 'github.com' (ED25519) to the list of known hosts.
remote: Enumerating objects: 213, done.
remote: Counting objects: 100% (148/148), done.
remote: Compressing objects: 100% (75/75), done.
remote: Total 213 (delta 67), reused 116 (delta 49), pack-reused 65
Receiving objects: 100% (213/213), 51.35 KiB | 559.00 KiB/s, done.
Resolving deltas: 100% (78/78), done.

❯ cd ansible-collection-wireguard/

❯ molecule create
INFO     default scenario test matrix: dependency, create, prepare
INFO     Performing prerun...
INFO     Set ANSIBLE_LIBRARY=/home/mike/.cache/ansible-compat/ce17b6/modules:/home/mike/.ansible/plugins/modules:/usr/share/ansible/plugins/modules
INFO     Set ANSIBLE_COLLECTIONS_PATH=/home/mike/.cache/ansible-compat/ce17b6/collections:/home/mike/.ansible/collections:/usr/share/ansible/collections
INFO     Set ANSIBLE_ROLES_PATH=/home/mike/.cache/ansible-compat/ce17b6/roles:roles:/home/mike/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles
INFO     Running ansible-galaxy collection install -v --force -p /home/mike/.cache/ansible-compat/ce17b6/collections .
INFO     Running default > dependency
INFO     Running ansible-galaxy collection install -v community.docker:>=1.9.1
WARNING  Skipping, missing the requirements file.
WARNING  Skipping, missing the requirements file.
INFO     Running default > create
WARNING  Skipping, instances already created.
INFO     Running default > prepare
WARNING  Skipping, instances already prepared.

❯ molecule create
INFO     default scenario test matrix: dependency, create, prepare
INFO     Performing prerun...
INFO     Set ANSIBLE_LIBRARY=/home/mike/.cache/ansible-compat/ce17b6/modules:/home/mike/.ansible/plugins/modules:/usr/share/ansible/plugins/modules
INFO     Set ANSIBLE_COLLECTIONS_PATH=/home/mike/.cache/ansible-compat/ce17b6/collections:/home/mike/.ansible/collections:/usr/share/ansible/collections
INFO     Set ANSIBLE_ROLES_PATH=/home/mike/.cache/ansible-compat/ce17b6/roles:roles:/home/mike/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles
INFO     Running ansible-galaxy collection install -v --force -p /home/mike/.cache/ansible-compat/ce17b6/collections .
WARNING  Retrying execution failure 250 of: ansible-galaxy collection install -v --force -p /home/mike/.cache/ansible-compat/ce17b6/collections .
ERROR    Command returned 250 code:
No config file found; using defaults
Starting galaxy collection install process
Process install dependency map
to see the full traceback, use -vvv

ERROR! Unexpected Exception, this is probably a bug: 'NoneType' object has no attribute 'items'

Traceback (most recent call last):
  File "/home/mike/.local/bin/molecule", line 8, in <module>
    sys.exit(main())
  File "/usr/lib/python3.10/site-packages/click/core.py", line 1137, in __call__
    return self.main(*args, **kwargs)
  File "/usr/lib/python3.10/site-packages/click/core.py", line 1062, in main
    rv = self.invoke(ctx)
  File "/usr/lib/python3.10/site-packages/click/core.py", line 1668, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/lib/python3.10/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/lib/python3.10/site-packages/click/core.py", line 763, in invoke
    return __callback(*args, **kwargs)
  File "/usr/lib/python3.10/site-packages/click/decorators.py", line 26, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/home/mike/.local/lib/python3.10/site-packages/molecule/command/create.py", line 119, in create
    base.execute_cmdline_scenarios(scenario_name, args, command_args)
  File "/home/mike/.local/lib/python3.10/site-packages/molecule/command/base.py", line 111, in execute_cmdline_scenarios
    scenario.config.runtime.prepare_environment(install_local=True)
  File "/home/mike/.local/lib/python3.10/site-packages/ansible_compat/runtime.py", line 325, in prepare_environment
    self.install_collection_from_disk(".", destination=destination)
  File "/home/mike/.local/lib/python3.10/site-packages/ansible_compat/runtime.py", line 229, in install_collection_from_disk
    self.install_collection(path, destination=destination, force=True)
  File "/home/mike/.local/lib/python3.10/site-packages/ansible_compat/runtime.py", line 222, in install_collection
    raise InvalidPrerequisiteError(msg)
ansible_compat.errors.InvalidPrerequisiteError: Command returned 250 code:
No config file found; using defaults
Starting galaxy collection install process
Process install dependency map
to see the full traceback, use -vvv

ERROR! Unexpected Exception, this is probably a bug: 'NoneType' object has no attribute 'items'

Hi @MonolithProjects

It's a bug of ansible instead of molecule, and ansible/ansible#77561 may fix this issue.

Hi @MonolithProjects

This PR ansible/ansible#77561 has been merged into ansible.

Could you please verify it?

If it passes, could you please close this issue.

Hi @zhan9san , yep it works with develop branch. Thx for fixing it...