Molecule config file in {project}/.config/molecule/config.yml not found
- Dominant language
- Python
- Stars
- 4.1k
- Forks
- 676
- Avg merge
- 4d 14h
- Merged PRs (30d)
- 9
Description
### Prerequisites
- [X] This was not already reported in the past (duplicate check)
- [X] It does reproduce it with code from main branch (latest unreleased version)
- [X] I include a minimal example for reproducing the bug
- [X] The bug is not trivial, as for those a direct pull-request is preferred
- [X] Running `pip check` does not report any conflicts
- [X] I was able to reproduce the issue on a different machine
- [X] The issue is not specific to any driver other than 'default' one
### Environment
OS Release: Red Hat 8.9
```
$molecule --version
molecule 6.0.3 using python 3.11
ansible:2.16.2
azure:23.5.0 from molecule_plugins
containers:23.5.0 from molecule_plugins requiring collections: ansible.posix>=1.3.0 community.docker>=1.9.1 containers.podman>=1.8.1
default:6.0.3 from molecule
docker:23.5.0 from molecule_plugins requiring collections: community.docker>=3.0.2 ansible.posix>=1.4.0
ec2:23.5.0 from molecule_plugins
gce:23.5.0 from molecule_plugins requiring collections: google.cloud>=1.0.2 community.crypto>=1.8.0
podman:23.5.0 from molecule_plugins requiring collections: containers.podman>=1.7.0 ansible.posix>=1.3.0
vagrant:23.5.0 from molecule_plugins
```
### What happened
**ISSUE:**
Molecule settings put into `{PROJECT_DIR}/.config/molecule/config.yml` are not found or used, but they are if I move `.config/molecule/.config.yml` to my user home directory.
**EXPECTATIONS:**
Molecule [documentation](https://ansible.readthedocs.io/projects/molecule/configuration/#prerun) states that we can put configurations into `{PROJECT_DIR}/.config/molecule/config.yml` or into `~/.config/molecule/config.yml` So both options should work.
**EXAMPLE:**
My example directory structure:
```
$ tree -a my_project/
my_project/
├── .config
│ └── molecule
│ └── config.yml
└── roles
└── somerole
└── molecule
└── default
├── converge.yml
├── create.yml
├── destroy.yml
└── molecule.yml
```
Here are the contents of `config.yml`:
```
---
driver:
name: docker
```
Here's what I see if I configure using `~/.config/molecule/config.yml` - it finds the file and the settings are used, this is good:
```
$ molecule converge
INFO Found config file /home/my_user/.config/molecule/config.yml
```
When I remove that `~/.config/molecule/config.yml` and only have `./my_project/.config/molecule/config.yml`it does not read these settings. I tried moving the .config directory to all different levels within the project dir with no luck.
**POSSIBLE SOLUTION**
I believe the issue lies in the `find_vcs_root` function in the file [util.py](https://github.com/ansible/molecule/blob/stable/6/src/molecule/util.py)
Adding `, ".config"` into the dirs variable in the `find_vcs_root` function definition line seems to resolve the issue for me:
```
def find_vcs_root(location="", dirs=(".git", ".hg", ".svn", ".config"), default=None) -> str:
```
I wanted to submit this as a PR as it seems fairly trivial but I am having issues getting my environment configured correctly. I apologize in advance if I did not contribute this exactly to the guidelines.
### Reproducing example
_No response_
Contributor guide
Research direction
Start in src/molecule/util.py at find_vcs_root and trace how molecule converge discovers configuration files. Run the provided project layout with molecule converge, then inspect existing tests for configuration discovery. Done means a project-local .config/molecule/config.yml is found and used while the home-directory configuration continues to work.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ansible, python
- Domain
- testing, tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100