Molecule config.yml not working in project root directory

I am working on setting up a project with Molecule and saw in the documentation 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:

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

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

$ 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

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

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

util.py

@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

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

I opened an issue here - I will mark this topic solved for now.

1 Like

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