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

after upgrading vagrant to 2.2.9 (from 2.2.7) a vagrant up destroys the domain on error #1122

Closed
rgl opened this issue Jun 10, 2020 · 3 comments

Comments

@rgl
Copy link
Contributor

rgl commented Jun 10, 2020

Steps to reproduce

  1. vagrant up with a provisioner that simply exit 1.

Expected behaviour

The libvirt domain/vm is not destroyed.

Actual behaviour

The libvirt domain/vm is destroyed when there is a provisioning error.

System configuration

OS/Distro version:: Ubuntu 20.04

Libvirt version:

Output of vagrant version; vagrant plugin list:

Installed Version: 2.2.9
Latest Version: 2.2.9
 
You're running an up-to-date version of Vagrant!

vagrant-libvirt (0.1.2, global)

Output of VAGRANT_LOG=debug vagrant ... --provider=libvirt

It seems vagrant is calling DestroyDomain:

 INFO warden: Calling IN action: #<VagrantPlugins::ProviderLibvirt::Action::DestroyDomain:0x00007fb9b8033b20>
 INFO interface: info: Removing domain...
 INFO interface: info: ==> default: Removing domain...
==> default: Removing domain...

the full log is at https://gist.github.com/rgl/1c849e1909435adb80af94bb43754a59

A Vagrantfile to reproduce the issue:

config.vm.provision 'shell', inline: 'exit 1'

Are you using upstream vagrant package or your distros package?

Upstream

@rgl
Copy link
Contributor Author

rgl commented Jun 10, 2020

The change in behavior was introduced at #984.

To restore the old behavior we just need to use the --no-destroy-on-error parameter when calling vagrnat up.

@rgl rgl closed this as completed Jun 10, 2020
@mattiasb
Copy link

mattiasb commented Dec 4, 2020

Since this has bitten me numerous times (and some machines take a long time to provision) I made a bash wrapper that ensure that --no-destroy-on-error is always set on the up command. Very lightly tested, so there may be bugs.

#!/bin/bash

function idx {
    local str a
    str="${1}"
    shift
    a=( "${@}" )
    for i in $(seq 0 "${#}"); do
        if [ "${str}" = "${a[i]}" ]; then
            echo "$((i + 1))"
            return 0
        fi
    done

    return 1
}

a=( "${@}" )
if i="$(idx up "${@}")"; then
    a=( "${a[@]:0:$i}" "--no-destroy-on-error" "${a[@]:$i}" )
fi

exec /usr/bin/vagrant "${a[@]}"

@zimmski
Copy link

zimmski commented Dec 26, 2020

Since the default with the VirtualBox provisioner is to keep the VM running, i was really confused for a long time what was happening and looked in all the wrong corners. I do not see any environment variable or configuration to disable the default of deleteing the VM. Is there? Because if not, i would have suspect this provisioner to work the same was as the VirtualBox one does.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants