Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Molecule generates wrong Vagrantfile when not defining 'provider' #66

Open
lukas-beumer opened this issue Aug 22, 2022 · 1 comment
Open
Labels

Comments

@lukas-beumer
Copy link

As we have different environments, where we need to run molecule tests. We have a curious problem.

We have defined the driver in molecule.yml:

driver:
  name: vagrant

Running our tests, molecule will choose the correct provider automatically. In our case virtualbox or libvirt. In default virtualbox is the default provider, but if it's not installed, libvirt will be chosen (if it's installed). The virtual machines will be setup, but not with the correct settings, if defined (like memory or cpus).

The problem is, that the underlying Vagrantfile will be generated for "virtualbox", even if it's not installed and the virtual machines were setup up for libvirt. Only if I define "libvirt" as provider in the molecule.yml, the file will be generated correctly. So the drive don't use the same driver as vagrant, if not set explicity

@apatard
Copy link
Member

apatard commented Aug 22, 2022

The problem is that it's vagrant itself which is choosing the "right" driver, and at time of writing the Vagrantfile, we have no way to know if vagrant will use a different driver. Vagrant will choose say libvirt instead of vbox when reading the Vagrantfile, which is too late, since here, it means when launching the VM.
The same problem may happen without molecule-vagrant. Just create a Vagrantfile for vmware driver and you'll likely see vagrant using vbox or libvirt.

There has been ansible-community/molecule-vagrant#174 about similar problem. I've suggested to have a rewrite to create an option to allow forcing the provider but nothing happened yet. Maybe I'll create a PR.

The other possibility would be to write the Vagrantfile, maybe use vagrant provider to check the provider which will be used and exit with an error if it's not the one configured ("fun point": this command possibly works at VM level not Vagrantfile). Also python-vagrant doesn't support the vagrant provider command, so it needs to be updated first. Possible, but complicated.

fwiw, the vagrant plugin command can't be used to detect that the provider is the correct one.

apatard referenced this issue in apatard/molecule-vagrant Sep 2, 2022
Currently, vagrant is still choosing the provider to use on its own
liking. While it's fine for cases like our CI or people who are fine
with default VM configurations, it's not always the case.

See:
- ansible-community#174
- https://github.com/ansible-community/molecule-vagrant/issues/181

So, add a new configuration setting to call vagrant up with
--provider, in order to force the provider to use and lead to an
error if it's not usable. The default value is to keep current
behaviour to not break things.

Signed-off-by: Arnaud Patard <[email protected]>
apatard referenced this issue in apatard/molecule-vagrant Sep 6, 2022
Currently, vagrant is still choosing the provider to use on its own
liking. While it's fine for cases like our CI or people who are fine
with default VM configurations, it's not always the case.

See:
- ansible-community#174
- https://github.com/ansible-community/molecule-vagrant/issues/181

So, add a new configuration setting to call vagrant up with
--provider, in order to force the provider to use and lead to an
error if it's not usable. The default value is to keep current
behaviour to not break things.

Signed-off-by: Arnaud Patard <[email protected]>
apatard referenced this issue in apatard/molecule-vagrant Sep 23, 2022
Currently, vagrant is still choosing the provider to use on its own
liking. This may cause troubles like VM memory/cpus or provider
options ignored if the provider use is not the one specified.

See:

- ansible-community#174
- https://github.com/ansible-community/molecule-vagrant/issues/181

So, pass --provider when the provider is set in the molecule.yml.
If the test doesn't care about the provider, it should remove the
provider name setting in the molecule.yml.

Note: While this may break some setup, I believe this will prevent
new reports/issues like the one previously noted. In case one
molecule.yml file for multiple providers is wanted, use the new
providers_options, as done in our CI scenario.

Signed-off-by: Arnaud Patard <[email protected]>
apatard referenced this issue in apatard/molecule-vagrant Oct 18, 2022
Currently, vagrant is still choosing the provider to use on its own
liking. This may cause troubles like VM memory/cpus or provider
options ignored if the provider use is not the one specified.

See:

- ansible-community#174
- https://github.com/ansible-community/molecule-vagrant/issues/181

So, pass --provider when the provider is set in the molecule.yml.
If the test doesn't care about the provider, it should remove the
provider name setting in the molecule.yml.

Note: While this may break some setup, I believe this will prevent
new reports/issues like the one previously noted. In case one
molecule.yml file for multiple providers is wanted, use the new
providers_options, as done in our CI scenario.

Signed-off-by: Arnaud Patard <[email protected]>
apatard referenced this issue in apatard/molecule-vagrant Jan 6, 2023
Currently, vagrant is still choosing the provider to use on its own
liking. This may cause troubles like VM memory/cpus or provider
options ignored if the provider use is not the one specified.

See:

- ansible-community#174
- https://github.com/ansible-community/molecule-vagrant/issues/181

So, pass --provider when the provider is set in the molecule.yml.
If the test doesn't care about the provider, it should remove the
provider name setting in the molecule.yml.

Note: While this may break some setup, I believe this will prevent
new reports/issues like the one previously noted. In case one
molecule.yml file for multiple providers is wanted, use the new
providers_options, as done in our CI scenario.

Signed-off-by: Arnaud Patard <[email protected]>
@ssbarnea ssbarnea transferred this issue from ansible-community/molecule-vagrant Jan 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants