# Molecule config.yml not working in project root directory

**URL:** <https://forum.ansible.com/t/molecule-config-yml-not-working-in-project-root-directory/4027>\
**Category:** Get Help\
**Tags:** molecule6, molecule\
**Created:** [February 23, 2024, 7:25pm UTC](https://forum.ansible.com/t/molecule-config-yml-not-working-in-project-root-directory/4027 "2024-02-23T19:25:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![eric\_hoog](https://avatars.discourse-cdn.com/v4/letter/e/b4bc9f/32.png) [@eric\_hoog](https://forum.ansible.com/u/eric_hoog)\
**Post date:** [February 23, 2024, 7:25pm UTC](https://forum.ansible.com/t/molecule-config-yml-not-working-in-project-root-directory/4027/1 "2024-02-23T19:25:02Z")

</div>

I am working on setting up a project with Molecule and saw in the [documentation](https://ansible.readthedocs.io/projects/molecule/configuration/#prerun) that we can put configurations into `{PROJECT_DIR}/.config/molecule/config.yml` or into `~/.config/molecule/config.yml` So I was doing a few tests to learn more.

I am having an issue where if I put settings into `{PROJECT_DIR}/.config/molecule/config.yml` they are not read but they are read if I move that directory to my user home directory.

Version Information:

```auto
>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

```

My example directory structure:

```auto
$ 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`:

```auto
---
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:

```auto
$ molecule converge
INFO Found config file /home/my_user/.config/molecule/config.yml

```

But when I remove that config in the home dir and leave it in my project root dir it does not read these settings. I tried moving the .config directory to all different levels within the project dir with no luck.

Am I doing something wrong or is this an issue in Molecule or the documentation?

Thanks for any assistance with this!  
-Eric

---

<div class="post-metadata">

**Author:** ![eric\_hoog](https://avatars.discourse-cdn.com/v4/letter/e/b4bc9f/32.png) [@eric\_hoog](https://forum.ansible.com/u/eric_hoog)\
**Post date:** [February 23, 2024, 8:04pm UTC](https://forum.ansible.com/t/molecule-config-yml-not-working-in-project-root-directory/4027/2 "2024-02-23T20:04:22Z")

</div>

Please note I’m not a python dev so I may be misunderstanding the code but I took a look at the source code and if I am reading it correctly I think I see the issue :

- The `find_vcs_root()` function has some arguments with default values: `location=""` and `default=None`
- The function then has logic to set `location` to the current working dir if `location=""`
- It does some other logic and then returns the value of `default` variable.
- It does not seem to me like the `default` variable ever gets updated in this function.
- When `find_vcs_root()` is called by `lookup_config_file()` it’s getting `default="~"` passed to it.
- It almost looks to me like `find_vcs_root()` will always only check the user home directory for `.config/molecule/config.yml`

Again I could be reading this completely wrong! If I am please let me know and if am right then let me know if I should raise an issue for this in the GitHub repo.

[shell.py](https://github.com/ansible/molecule/blob/stable/6/src/molecule/shell.py)

```auto
LOCAL_CONFIG_SEARCH = ".config/molecule/config.yml"
LOCAL_CONFIG = lookup_config_file(LOCAL_CONFIG_SEARCH)

```

[util.py](https://github.com/ansible/molecule/blob/stable/6/src/molecule/util.py)

```auto
@cache
def find_vcs_root(location="", dirs=(".git", ".hg", ".svn"), default=None) -> str:
    """Return current repository root directory."""
    if not location:
        location = os.getcwd()
    prev, location = None, os.path.abspath(location)
    while prev != location:
        if any(os.path.isdir(os.path.join(location, d)) for d in dirs):
            return location
        prev, location = location, os.path.abspath(os.path.join(location, os.pardir))
    return default

def lookup_config_file(filename: str) -> str | None:
    """Return config file PATH."""
    for path in [find_vcs_root(default="~"), "~"]:
        f = os.path.expanduser(f"{path}/{filename}")
        if os.path.isfile(f):
            LOG.info("Found config file %s", f)
            return f
    return None

```

---

<div class="post-metadata">

**Author:** ![eric\_hoog](https://avatars.discourse-cdn.com/v4/letter/e/b4bc9f/32.png) [@eric\_hoog](https://forum.ansible.com/u/eric_hoog)\
**Post date:** [February 24, 2024, 12:09am UTC](https://forum.ansible.com/t/molecule-config-yml-not-working-in-project-root-directory/4027/3 "2024-02-24T00:09:59Z")

</div>

I’m going to raise an issue in the project on GitHub as I feel like that is a better place to track this.

---

<div class="post-metadata">

**Author:** ![eric\_hoog](https://avatars.discourse-cdn.com/v4/letter/e/b4bc9f/32.png) [@eric\_hoog](https://forum.ansible.com/u/eric_hoog)\
**Post date:** [February 24, 2024, 7:30am UTC](https://forum.ansible.com/t/molecule-config-yml-not-working-in-project-root-directory/4027/4 "2024-02-24T07:30:49Z")

</div>

I opened an issue here - I will mark this topic solved for now.  
[https://github.com/ansible/molecule/issues/4142](https://github.com/ansible/molecule/issues/4142)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [March 25, 2024, 7:31am UTC](https://forum.ansible.com/t/molecule-config-yml-not-working-in-project-root-directory/4027/5 "2024-03-25T07:31:04Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
