Vagrant is a tool for building and managing virtual machine environments in a single workflow.
The tool provides a portable, reproducible and easy to configure work environments built on top of industry-standard technology. Machines are provisioned on top of VirtualBox, VMware, Scaleway, or any other provider.
1 . Download the latest version of Vagrant for your operating system.
2 . Launch the installation tool and follow the steps to install it on your local computer.
3 . Verify that the installation has completed successfully by launching the command
$ vagrant -v Vagrant 2.2.0
Prepacked templates of virtual machines are called Boxes in Vagrant. You can find a full list of all public boxes on the box search page.
Important Vagrant Boxes are build for certain hypervizors and may not be universally compatible. Check the box search page to verify, if the Box is compatible with your hypervizor. Alternatively you may use Bento Boxes, these boxes are open source and built for a number of providers including VMware, Virtualbox, and Parallels. There are a variety of operating systems and versions available.
1 . Create a new directory for your Vagrant project and enter it:
mkdir -p vagrant-projects/ubuntu-vm cd vagrant-projects/ubuntu-vm
2 . Initialize a new Vagrant environment inside the projects directory with the command
vargrant init <boxpath>, where
vagrant init bento/ubuntu-18.04
3 . Start the new virtual machine:
Runnig the vagrant up command creates, configures and starts a virtual machine as described in your Vagrantfile.
During the first run the tool downloads automatically the required Vagrant box from the box repository and performs provisioning of the machine.
4 . Log into your box by using SSH:
vagrant ssh default
You can now run any tasks on your virtual machine and develop your application.
Once you have finished your work on the virtual machine, you have several options to stop or to destroy it if you do not need it any longer.
5 . To stop the virtual machine, type:
6 . To hibernate the machine, type:
7 . If you want to delete your VM, type:
To recreate a VM from the configuration in your Vagrantfile simply type:
You can modify the Vagrantfile to customize the provision of virtual machines towards your needs.
To update your default Ubuntu to the latest version and to install the Apache web server automatically, uncomment the following lines as following in your Vagrantfile and save it:
# Enable provisioning with a shell script. Additional provisioners such as # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the # documentation for more information about their specific syntax and use. config.vm.provision "shell", inline: <<-SHELL apt-get update apt-get install -y apache2 SHELL end
Now you can recreate your VM with and follow the update of the system as well as the installation of Apache:
You can use a plugin that allows you to provide Scaleway Instances directly from your Vagrantfile.
1 . Create a new folder for your project:
2 . Install the plugin with Vagrant:
vagrant plugin install vagrant-scaleway
3 . Create a Vagrantfile that is looking like the following example:
Vagrant.configure('2') do |config| config.vm.provider :scaleway do |scaleway, override| config.vm.synced_folder '.', '/vagrant', disabled: true scaleway.organization = 'YOUR_ORGANIZATION_UUID' scaleway.token = 'YOUR_TOKEN' scaleway.name = 'YOUR_SERVER_NAME' scaleway.commercial_type = 'GP1-S' scaleway.region = 'PAR1' scaleway.image = 'IMAGE_ID' override.ssh.private_key_path = '~/.ssh/id_rsa' end end
You may check this RubyDoc for all configuration options.
4 . Once you have finished the work on your Vagrantfile, you can deploy the instance by typing:
You will see an output like the following:
Bringing machine 'default' up with 'scaleway' provider... ==> default: Creating a server with the following settings... ==> default: -- Commercial Type: GP1-S ==> default: -- Image: db52018e-b3c0-4676-94a0-c40ba3f4a282 ==> default: -- Name: scw-vagrant-server ==> default: Starting the server... ==> default: Waiting for server to become "ready"... ==> default: Waiting for SSH to become available... ==> default: Machine is booted and ready for use!
5 . You can now log into your server:
And you will see an output like the following, meaning that you are connected to your Scaleway instance now:
___ ___ __ _| | _____ ____ _ _ _ / __|/ __/ _` | |/ _ \ \ /\ / / _` | | | | \__ \ (_| (_| | | __/\ V V / (_| | |_| | |___/\___\__,_|_|\___| \_/\_/ \__,_|\__, | |___/ Welcome on Ubuntu Bionic Beaver (18.04 LTS) (GNU/Linux 4.9.93-mainline-rev1 x86_64 ) System information as of: Thu Nov 8 11:05:14 UTC 2018 System load: 0.02 Int IP Address: 10.16.123.234 Memory usage: 0.0% Pub IP Address: 188.8.131.52 Usage on /: 4% Swap usage: 0.0% Local Users: 0 Processes: 103 Image build: 2018-07-03 System uptime: 1:02 hours Disk vda: l_ssd 50G
For more information how to manage your virtual machines with Vagrant, you may check out the official documentation.