Skip to content

Commit

Permalink
[PATCH] driver.provider.name Overrided by VAGRANT_DEFAULT_PROVIDER
Browse files Browse the repository at this point in the history
In case environment variable `VAGRANT_DEFAULT_PROVIDER` is defined (see
<https://www.vagrantup.com/docs/other/environmental-variables#vagrant_default_provider>),
our `driver.provider.name` will have no effect and always start with
above default provider as specifiied.

With python-vagrant `up()` (see
<https://github.com/pycontribs/python-vagrant/blob/main/src/vagrant/__init__.py#L310-L318>)
we could specify the target provider with `provider` option, where our
current wrapper only provide the `provision` option.

See ansible-community/molecule-vagrant#174

Signed-off-by: Wong Hoi Sing Edison <hswong3i@pantarei-design.com>
  • Loading branch information
hswong3i committed Jan 23, 2025
1 parent 613b885 commit 34ae076
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/molecule_plugins/vagrant/modules/vagrant.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ def merge_dicts(a: MutableMapping, b: MutableMapping) -> MutableMapping:
class VagrantClient:
def __init__(self, module) -> None:
self._module = module
self.provider = self._module.params["provider_name"]
self.provision = self._module.params["provision"]
self.cachier = self._module.params["cachier"]

Expand Down Expand Up @@ -456,9 +457,10 @@ def up(self):
changed = False
if self._running() != len(self.instances):
changed = True
provider = self.provider
provision = self.provision
with contextlib.suppress(Exception):
self._vagrant.up(provision=provision)
self._vagrant.up(provider=provider, provision=provision)

# NOTE(retr0h): Ansible wants only one module return `fail_json`
# or `exit_json`.
Expand Down Expand Up @@ -714,7 +716,7 @@ def main():
"provider_options": {"type": "dict", "default": {}},
"provider_override_args": {"type": "list", "default": None},
"provider_raw_config_args": {"type": "list", "default": None},
"provider_name": {"type": "str", "default": "virtualbox"},
"provider_name": {"type": "str", "required": False, "default": "virtualbox"},
"default_box": {"type": "str", "default": None},
"provision": {"type": "bool", "default": False},
"force_stop": {"type": "bool", "default": False},
Expand Down

0 comments on commit 34ae076

Please sign in to comment.