I can run "vagrant box outdated" to see the list of boxes that need to be updated.
I can run "vagrant box update" that will update these boxes.
I really want to have an easy way to remove the now outdated boxes.
I would be fine with scripting this if I knew how to take the output of one vagrant command and feed it into another...
If Implement this feature, how would you prefer that it be accessed from the command-line?
Here are some options I thought about:
vagrant box update --remove-outdated [provider]
vagrant box remove --outdated [provider]
Suggestions?
Plusing this request. I think "remove --outdated" could be enough.
Can you just create a pull request for your proposal?
:+1:
@chrisvire This would be an awesome addition!
In the meantime you can use this command -->
curl -LSs http://bit.ly/box-update-all | bash
which will update all your base boxes and remove all old versions.
Has anyone started on this implementation?
This feature would help me a lot so i decided to give it a go. I pretty much have it working, and will make a pull request soon hopefully.
I ended up doing a command since putting i tinto the other commands felt weird. It seemed they differ quite a lot in scope or purpose.
vagrant box remove-old-versions --provider docker
I probably use the internal action to remove the boxes so it is less new code. So i might also add some more options like confirming.
Well i made a pull request #6863. I might also extract this to a seperate plugin so the feature can be used while we wait what is said about the pull request.
Ok, i've also created a plugin with this feature. Ready to install to your local vagrant :)
@bbrala - That is amazing! Thank you for your efforts, you've saved me several days of work!
@bbrala Well done. Waiting for merge.
+1
@bbrala great work! I have installed your plugin and works like a charm. Thanks!
@bbrala - this is excellent - your PR should definitely be merged - works great (vagrant 1.7.4)
Added tests for all options except --force. And i added the options --dry-run and --name which were contributed to the plugin. Think everything should be ready for a merge.
Ping @sethvargo
@sethvargo is there any timeline on which this might be merged or at least reviewed?
The docs are correct versus the current feature set.
The request is to add a feature (integrating Bjorn's excellent plugin) so
it's in the base vagrant product without 'needing' to add a plugin. That
would require a docs update to match of course.
On Fri, Apr 22, 2016 at 11:52 PM, Joandi Leonardus <[email protected]
wrote:
is there any question to this documentation?
PRUNING OLD VERSIONS
_Vagrant does not automatically prune old versions because it does not
know if they might be in use by other Vagrant environments._ Because
boxes can be large, you may want to actively prune them once in awhile
using vagrant box remove. You can see all the boxes that are installed
using vagrant box list.—
You are receiving this because you commented.
Reply to this email directly or view it on GitHub
https://github.com/mitchellh/vagrant/issues/4412#issuecomment-213676113
----- [email protected] ----
Is there any update on this?
The PR has been tagged 2.0.0 recently, this means it will take a while before it might be merged. For now, i'd advise you to use the plugin i made, which is literally the same functionality as the PR i made for this issue.
Vagrant has the functionality there, but I can't seem to find anything about putting it in a vagrantfile.
Is there any current way to add an auto-removal of old boxes after update right in the vagrantfile, so all my devs can keep up to date painlessly?
Hi @byanke-pcn,
We use vagrant-triggers plugin for that:
if Vagrant.has_plugin?("vagrant-triggers")
config.trigger.after :destroy do
run "vagrant box prune --name company-name/box-name"
end
end
But anyways the workflow is:
$ vagrant destroy -f
$ vagrant box update
$ vagrant up
[_I'm byanke-pcn/ghost above, I consolidated accounts_]
I've been running the triggers commands, as well as running the prune manually, but I still end up with base boxes on my filesystem and appearing in virtualbox. For me, the prune seems to just be removing it from vagrant's interface, not from the computer.
Assistance?
The prune command will internally run vagrant box remove [box] which removes it from the vagrant repository of boxes. Normally you find those in ~/vagrant.d/boxes.
If you mean removing them from your list of instances in VirtualBox you might have misunderstood the command. It will remove all old versions of installed boxed, and will not remove old instances from your VirtualBox (the machines created by vagrant up).
Is there any way to do so? Currently, as I understand it, vagrant can create but not delete boxes, which means it can't really fully automate the process, and must leave behind cruft.
vagrant destroy in the correct project should just remove them :)
It doesn't though....
I run a destroy and prune nightly, and an up every morning (at least, sometimes I rebuild the box during the day too). After two weeks, I have several spare boxes just sitting in virtualbox taking up space.
@benyanke are you using linked clone mode?
Yes.
That might be a factor here.
There is an open issue about linked clones not getting cleaned somewhere in the issues actually. So yeah that is probably why then.
See #8277
I'm going to lock this issue because it has been closed for _30 days_ ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.
Most helpful comment
Ok, i've also created a plugin with this feature. Ready to install to your local vagrant :)
https://github.com/swisnl/vagrant-remove-old-box-versions