molecule icon indicating copy to clipboard operation
molecule copied to clipboard

Expose --base-config as an environment variable

Open tiilikainen opened this issue 5 years ago • 8 comments

Issue Type

  • Feature request

Molecule and Ansible details

ansible --version && molecule --version
ansible 2.7.5
  config file = None
  configured module search path = ['/Users/stiilikainen/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /Users/stiilikainen/.local/share/virtualenvs/a9y-iac-GOXhPMtO/lib/python3.7/site-packages/ansible
  executable location = /Users/stiilikainen/.local/share/virtualenvs/a9y-iac-GOXhPMtO/bin/ansible
  python version = 3.7.2 (default, Dec 27 2018, 07:35:06) [Clang 10.0.0 (clang-1000.11.45.5)]
molecule, version 2.19.0

Molecule installation method (one of):

  • pip

Ansible installation method (one of):

  • pip

Desired Behavior

I would like the --base-config option to be exposed as an environment variable. The use case would be that I could put this variable in .env.yml in my project root and thus have a project-specific base config that I wouldn't have to specify on the command line.

MOLECULE_BASE_CONFIG=./base.yml

Directory structure this would support:

project/
  - .env.yml
  - base.yml
  - molecule/
    - scenario1/
      - molecule.yml
    - scenario2/
      - molecule.yml

tiilikainen avatar Jan 14 '19 15:01 tiilikainen

Hi @tiilikainen, thanks for raising. Right now, you can do this by treating your molecule/default/molecule.yml as the base configuration and then passing relative paths to shared configurations across all scenarios. Is this not solving your need? Can you explain further why you might need this central configuration file?

decentral1se avatar Jan 15 '19 23:01 decentral1se

Ah, sorry, I misunderstood that we already had this --base-config! My question above still stands but is unrelated for this issue ;) Yes, in this case, it looks like we should expose this as an env var. I've just seen a bug related to the configuration via https://github.com/ansible/molecule/issues/1661.

decentral1se avatar Jan 16 '19 11:01 decentral1se

@tiilikainen, in your usage of this option, are you seeing anything like what is being reported in #1661?

decentral1se avatar Jan 20 '19 23:01 decentral1se

Hi,

  1. I have a few interrelated roles from which I’d like to abstract a common base config.

  2. Yes, I’ve been able to replicate that bug.

tiilikainen avatar Jan 22 '19 00:01 tiilikainen

Would be also possible to have this option in configuration?

When I have monorepo with multiple roles with one common molecule.yml file, I would like to run for example only molecule converge instead of molecule --base-config ../../molecule-common/molecule.yml converge.

I can also see sourcing some env file as solution, but this is kinda same as having a configuration file. But with configuration file I don't need to do this one source manual step.

Lirt avatar May 22 '19 08:05 Lirt

Fancy submitting a PR @Lirt? Both requests seem reasonable to me ...

decentral1se avatar May 22 '19 09:05 decentral1se

Anyone know if this have been implemented since May? We would also like this, since we have a mono-repo..

xeor avatar Sep 20 '19 12:09 xeor

One way how to do that is alias moleculeb="molecule --base-config .config/molecule/config.yml" Basically just by creating custom alias. It can be temporary in current terminal or permanently in your .profile, .zprofile or what have you.

Then just use it like moleculeb converge -s dev -- --limit workstations --tags nvim

But for sure, exposed MOLECULE_BASE_CONFIG would be much much nicer and idiomatic solution.

dzintars avatar Feb 02 '23 21:02 dzintars