ansible/molecule

CRITICAL 'molecule/default/molecule.yml' glob failed. Exiting - Unable to run molecule

iamgini opened this issue Β· 14 comments

Prerequisites

  • This was not already reported in the past (duplicate check)
  • It does reproduce it with code from main branch (latest unreleased version)
  • I include a minimal example for reproducing the bug
  • The bug is not trivial, as for those a direct pull-request is preferred
  • Running pip check does not report any conflicts
  • I was able to reproduce the issue on a different machine
  • The issue is not specific to any driver other than 'default' one

Environment

$ ansible --version
ansible [core 2.16.2]
  config file = /home/iamgini/.ansible.cfg
  configured module search path = ['/home/iamgini/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.12/site-packages/ansible
  ansible collection location = /home/iamgini/collections:/home/iamgini/.ansible/collections/ansible_collections:/usr/share/ansible/collections/ansible_collections:/home/iamgini/ansible/ansible-real-life/ansible-molecule-demo/collections/ansible_collections
  executable location = /usr/bin/ansible
  python version = 3.12.1 (main, Dec 18 2023, 00:00:00) [GCC 13.2.1 20231205 (Red Hat 13.2.1-6)] (/usr/bin/python3)
  jinja version = 3.1.2
  libyaml = True

What happened

I have a collection with molecule configured and its working perfectly in one folder.
Now I am trying to copy the molecule setup for another collection but facing the below error.

$ molecule create
CRITICAL 'molecule/default/molecule.yml' glob failed.  Exiting.

$ molecule test
CRITICAL 'molecule/default/molecule.yml' glob failed.  Exiting.

$ molecule reset
CRITICAL 'molecule/default/molecule.yml' glob failed.  Exiting.

$ molecule destroy
CRITICAL 'molecule/default/molecule.yml' glob failed.  Exiting.

I tried:

  1. re-copy the working extensions folder from another working collection dir but getting same result!
  2. Freshly done molecule init scenario

Any idea?

Reference code: https://github.com/iamgini/ansible-real-life/tree/main/ansible-molecule-demo

Reproducing example

No response

@iamgini, it is hard for us to reproduce the scenario. Is it possible for you to provide more info on the setup, or maybe if you could create a branch with the setups, we can reproduce the error?

I have the same error but maybe in little different case.
When I initialized scenario default and then deleted the folder with that, I was trying to do molecule reset and got CRITICAL 'molecule/default/molecule.yml' glob failed. Exiting.

@shameoff my apologies for the very late response here!
For me, the molecule reset also giving the same result.

$ molecule reset
CRITICAL 'molecule/default/molecule.yml' glob failed.  Exiting.
```|

Update: I have initiated a separate repo (root/project directory) and repeated the steps and its working!!!

no idea what is the problem with the other folder!

Hope the dev team can give more details verbose option rather than a single line `CRITICAL 'molecule/default/molecule.yml' glob failed.  Exiting.`

I think the error message means that no directory named molecule/default/molecule.yml exists. Sometimes this happens to me when I am running molecule while in the wrong current working directory.

Looking at your reference code, I see that there is no molecule/default/molecule.yml, but extensions/molecule/default/molecule.yml

(assuming that the collection in question is in ansible-real-life/ansible-molecule-demo/ansible-devspaces-demo-brandor5/collections/ansible_collections/sample_namespace/sample_collection)

I have the same issue. But I found out what was causing itβ€”for me at least. When I run any molecule command and the molecule/default/molecule.yml file is listed in my .gitignore file, I get the error. After I remove the line in the .gitignore file, all commands work just fine. It is only the molecule.yml file. Every other Molecule file can be listed in the .gitignore file, and it works.

I am using Molecule inside a dev container. Let me know if you need the config for it.

Confirming that removing molecule/default/molecule.yml from .gitignore worked for me as well. I'm using molecule from venv but it's a linux on bare metal. Any idea to why is it causing the issue?

I was having thas same error as you had.
Scenario of the error I was having (simplified but the error was the same)

  1. molecule init scenario my_role
    Change the files as you need or add you role or files .
  2. Had the structure like this (basic one)
 tree 
.
└── molecule
    └── my_role
        β”œβ”€β”€ converge.yml
        β”œβ”€β”€ create.yml
        β”œβ”€β”€ destroy.yml
        └── molecule.yml

2 directories, 4 files

  1. If you execute from the top folder (not inside molecule and not inside my_role) molecule converge it gives the error, you need to add the -s so the command is: molecule converge -s my_role

Steps to reproduce

  1. molecule init scenario my_role
  2. molecule converge -s my_role (you can change with no problem to create, destroy..)
    Dont use the molecule converge with no scenario defined because it looks for default scenario and gives the CRITICAL error

Steps to reproduce having multiple roles inside one molecule scenario

In the case you want to have multiple roles inside one molecule folder, like this:

tree molecule/
molecule/
β”œβ”€β”€ my_role
β”‚   β”œβ”€β”€ converge.yml
β”‚   β”œβ”€β”€ create.yml
β”‚   β”œβ”€β”€ destroy.yml
β”‚   └── molecule.yml
└── my_role_2
    β”œβ”€β”€ converge.yml
    β”œβ”€β”€ create.yml
    β”œβ”€β”€ destroy.yml
    └── molecule.yml

2 directories, 8 files

To run my_role -> molecule converge -s my_role
To run my_role_2 -> molecule converge -s my_role_2

To reset my_role_1-> Below

molecule reset -s my_role
INFO     my_role scenario test matrix: 
INFO     Performing prerun with role_name_check=0...
INFO     Removing /home/myuser/.cache/molecule/tmp/my_role

I have tried also adding a .gitignore with this content:
molecule/
in the same directory as molecule folder and have 0 problems.

I was having thas same error as you had. Scenario of the error I was having (simplified but the error was the same)

  1. molecule init scenario mi_rol_ansible
    Change the files as you need
  2. Had the structure like this
 tree 
.
└── molecule
    └── my_role
        β”œβ”€β”€ converge.yml
        β”œβ”€β”€ create.yml
        β”œβ”€β”€ destroy.yml
        └── molecule.yml

2 directories, 4 files
  1. Tried with molecule converge from molecule direcotory, from my role directory and from converge, verify directory, always had the same error: CRITICAL 'molecule/default/molecule.yml' glob failed. Exiting.

The solution is really straighforward, just create molecule and default directories inside the role, like this

tree molecule/
molecule/
└── my_role
    └── molecule
        └── default
            β”œβ”€β”€ converge.yml
            β”œβ”€β”€ create.yml
            β”œβ”€β”€ destroy.yml
            └── molecule.yml

3 directories, 4 files

Execute molecule converge from /my_role directory and it works

Did you mean to use separate molecule content for each roles?

#4117 (comment)

@iamgini Hey!, I have just updated the comment, now is more clear and straight forward with an example with two roles inside one molecule scenario, let me know if that helps you

@valkiriaaquatica oh ok. This is also good.

Our approach is a common molecule directory

β”œβ”€β”€ ansible.cfg
β”œβ”€β”€ collections
β”‚   └── ansible_collections
β”‚       β”œβ”€β”€ iamgini
β”‚       β”‚   β”œβ”€β”€ meetupdemo
β”‚       β”‚   β”‚   β”œβ”€β”€ docs
β”‚       β”‚   β”‚   β”œβ”€β”€ extensions
β”‚       β”‚   β”‚   β”‚   └── molecule
β”‚       β”‚   β”‚   β”‚       └── default
β”‚       β”‚   β”‚   β”‚           β”œβ”€β”€ backup
β”‚       β”‚   β”‚   β”‚           β”‚   └── prepare.yml
β”‚       β”‚   β”‚   β”‚           β”œβ”€β”€ converge.yml
β”‚       β”‚   β”‚   β”‚           β”œβ”€β”€ create.yml
β”‚       β”‚   β”‚   β”‚           β”œβ”€β”€ destroy.yml
β”‚       β”‚   β”‚   β”‚           β”œβ”€β”€ molecule.yml
β”‚       β”‚   β”‚   β”‚           β”œβ”€β”€ requirements.yml
β”‚       β”‚   β”‚   β”‚           β”œβ”€β”€ tasks
β”‚       β”‚   β”‚   β”‚           β”‚   └── create-fail.yml
β”‚       β”‚   β”‚   β”‚           └── verify.yml
β”‚       β”‚   β”‚   β”œβ”€β”€ galaxy.yml
β”‚       β”‚   β”‚   β”œβ”€β”€ meta
β”‚       β”‚   β”‚   β”‚   └── runtime.yml
β”‚       β”‚   β”‚   β”œβ”€β”€ playbooks
β”‚       β”‚   β”‚   β”‚   └── install_web.yaml
β”‚       β”‚   β”‚   β”œβ”€β”€ plugins
β”‚       β”‚   β”‚   β”‚   └── README.md
β”‚       β”‚   β”‚   β”œβ”€β”€ README.md
β”‚       β”‚   β”‚   └── roles
β”‚       β”‚   β”‚       └── web
β”‚       β”‚   β”‚           β”œβ”€β”€ defaults
β”‚       β”‚   β”‚           β”‚   └── main.yml
β”‚       β”‚   β”‚           β”œβ”€β”€ files
β”‚       β”‚   β”‚           β”œβ”€β”€ handlers
β”‚       β”‚   β”‚           β”‚   └── main.yml
β”‚       β”‚   β”‚           β”œβ”€β”€ meta
β”‚       β”‚   β”‚           β”‚   └── main.yml
β”‚       β”‚   β”‚           β”œβ”€β”€ README.md
β”‚       β”‚   β”‚           β”œβ”€β”€ tasks
β”‚       β”‚   β”‚           β”‚   └── main.yml
β”‚       β”‚   β”‚           β”œβ”€β”€ templates
β”‚       β”‚   β”‚           β”œβ”€β”€ tests
β”‚       β”‚   β”‚           β”‚   β”œβ”€β”€ inventory
β”‚       β”‚   β”‚           β”‚   └── test.yml
β”‚       β”‚   β”‚           └── vars

@iamgini thanks for the info. I've just created your example asi is shown below (quick approach) but instead of giving the inside folder of molecule the default value i changed it to my_rol_of_iamgini (execute the molecule init scenario my_rol_of_iamgini) .

myuser@ubuntu-dev:/tmp$ tree ansible_collections/
ansible_collections/
└── iamgini
    └── meetupdemo
        β”œβ”€β”€ docs
        β”œβ”€β”€ extensions
        β”‚   └── molecule
        β”‚       └── my_rol_of_iamgini
        β”‚           β”œβ”€β”€ backup
        β”‚           β”‚   └── prepare.yml
        β”‚           β”œβ”€β”€ converge.yml
        β”‚           β”œβ”€β”€ create.yml
        β”‚           β”œβ”€β”€ destroy.yml
        β”‚           β”œβ”€β”€ molecule.yml
        β”‚           β”œβ”€β”€ requirements.yml
        β”‚           β”œβ”€β”€ tasks
        β”‚           β”‚   └── create-fail.yml
        β”‚           └── verify.yml
        β”œβ”€β”€ galaxy.yml
        β”œβ”€β”€ meta
        β”‚   └── runtime.yml
        β”œβ”€β”€ playbooks
        β”‚   └── install_web.yml
        β”œβ”€β”€ plugins
        β”‚   └── README.md
        └── roles
            └── web
                β”œβ”€β”€ defaults
                β”‚   └── main.yml
                β”œβ”€β”€ files
                β”œβ”€β”€ handlers
                β”‚   └── main.yml
                β”œβ”€β”€ meta
                β”‚   └── main.yml
                β”œβ”€β”€ README.md
                β”œβ”€β”€ tasks
                β”‚   └── main.yml
                β”œβ”€β”€ templates
                β”œβ”€β”€ tests
                β”‚   β”œβ”€β”€ inventory
                β”‚   └── test.yml
                └── vars
                    └── main.yml

20 directories, 21 files

Then i move to route below and exexute the following

myuser@ubuntu-dev:/tmp/ansible_collections/iamgini/meetupdemo/extensions$ ls
molecule
myuser@ubuntu-dev:/tmp/ansible_collections/iamgini/meetupdemo/extensions$ molecule converge -s my_rol_of_iamgini
INFO     my_rol_of_iamgini scenario test matrix: dependency, create, prepare, converge
INFO     Performing prerun with role_name_check=0...
INFO     Running my_rol_of_iamgini > dependency

Hope it helps you

As was mentioned by @Ic0n4, Molecule fails to find the glob if the molecule files are under a folder in .gitignore:

I have the same issue. But I found out what was causing itβ€”for me at least. When I run any molecule command and the molecule/default/molecule.yml file is listed in my .gitignore file, I get the error. After I remove the line in the .gitignore file, all commands work just fine. It is only the molecule.yml file. Every other Molecule file can be listed in the .gitignore file, and it works.

Is there any reason for this? I have a use case where I want my molecule files to not be checked into version control. This behavior seems unintentional to me.

I had this problem when I accidentally named the parent directory extension instead of extensions and I was in the directory:

❯ cd extension
❯ molecule test --all
CRITICAL 'molecule/*/molecule.yml' glob failed.  Exiting.
❯ cd ..
❯ mv extension{,s}
❯ cd extensions
❯ molecule test --all
WARNING  Driver podman does not provide a schema.
INFO     Performing prerun with role_name_check=0...
INFO     Running nginx > dependency
WARNING  Skipping, missing the requirements file.
WARNING  Skipping, missing the requirements file.