My even more flexible Vagrant IDE

Martien van den Akker
Nerd For Tech
Published in
3 min readJan 24, 2024

You may know that I have improved my Vagrant/VirtualBox projects on a regular basis. One of those is my Oracle Linux 8 Develop project, that is an evoluted project from earlier Red Hat/CentOS based ones, as can be read in my earlier article Check out my upgraded Vagrant project.

Lately, I migrated my article about My boxes in the Vagrant Cloud to Medium. And I found that I could improve my Oracle Linux 8 Develop project, to make it more flexible. A few years ago I already abstracted the settings to a separate settings.yml YAML file. When you change a file with a pull Git would not update it. For example, if you change some of the settings, because you want to allocate a different amount of memory, or other shared folder locations, you would not get other functionality or improvements, like provisioners, that I may have added.

In the same way I extracted the provisioners into a provisioners.yml YAML file.

Looping over Provisioners

Until now, I needed to add each provisioner in the YAML file also in as a reference in the Vagrantfile. For each provisioner in the YAML, I had to explicitly call the provision function with a reference to the particular provisioner. So, adding a provisioner, meant changing both files.

I figured that Ruby, the language used for the Vagrant file, would support looping as well. And so, I changed the list of provisioners in the Vagrant file with a loop. This way, adding provisioners would only mean to extend the provisioners.yml file.

In the loop I also have vagrant print the added provisioner, so you could run it easily again.

Looping over shared folders and provisioners

Extendable list of Shared Folders

Until now, my Vagrant project only supported 2 fixed shared folders: stage and project. The stage folder is mandatory, because the provisioners rely on the location of the provision scripts, based on this folder. The projects folder was an extra, to have a means to exchange data between the VM and the host. But you may want to name it differently or have other, additional sharedFolders. Again, until now this meant changing both the settings.yml and the Vagrantfile. Now, you can add as many sharedFolders as you want:

sharedFolders:
stage:
host: c:/Data/git/makker/vagrant/Stage
guest: /media/sf_Stage
project:
host: c:/Data/projects
guest: /media/sf_Projects

Or change or remove the projects. Mind, that you should keep the stage folder entry. You may however change the host and guest attributes, provided that they lead to a valid sharedFoder mount.

Conclusion

These improvements make my Vagrant project even more flexible. And my Vagrantfile cleaner.

If you happen to use my project already, and you have did changes to one of the files, you may want to backup those changes and revert them before a git pull. Then re-apply the necessary changes.

I hope you may enjoy using my Vagrant project. At least I do. Next, I may need to follow up on my article My boxes in the Vagrant Cloud and create a new version of the Oracle Linux 8 box.

--

--

Nerd For Tech
Nerd For Tech

Published in Nerd For Tech

NFT is an Educational Media House. Our mission is to bring the invaluable knowledge and experiences of experts from all over the world to the novice. To know more about us, visit https://www.nerdfortech.org/.

Martien van den Akker
Martien van den Akker

Written by Martien van den Akker

Technology Architect at Oracle Netherlands. The views expressed on this blog are my own and do not necessarily reflect the views of Oracle

No responses yet