Vagrant to orchestrate ubuntu in VirtualBox installing boto3 and Ansible

At the time of this post, the compatibility matrix of vagrant and VirtualBox is as follows:

Vagrant versionVirtualBox version
Vagrant and Virtualbox compatibility matrix

Unfortunately, Vagrant 2.4.0 does not work well with VirtualBox 7.0

This post was created using Vagrant 2.3.7 and VirtualBox 7.0.10

To make Vagrant possible, after installing the Vagrant from hashicorp webpage, a Vagrant file needs to be created. The most basic file that needs to exist in your Vagrant to work is a folder with Vagrantfile

Additional post start up scripts to complete the installations that are used in this example are,, and

Vagrantfile file content

# Check and install plugin to orchestrate vbox
unless Vagrant.has_plugin?("vagrant-vbguest")
  exec "vagrant plugin install vagrant-vbguest"

unless Vagrant.has_plugin?("vagrant-hostmanager")
  exec "vagrant plugin install vagrant-hostmanager"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|  
  # ubuntu 20.04 LTS = "ubuntu/focal64"
  config.vm.define "docker-ubuntu"
  config.vm.hostname = "dockerized-ubuntu-vm" "private_network", type: "dhcp"
  # Commented as its a standalone ubuntu box which has no web services :forwarded_port, guest: 80, host: 80 :forwarded_port, guest: 443, host: 443

  config.vm.provider "virtualbox" do |vb|
    # Boot with headless mode
    vb.gui = false    # Tweak the below value to adjust RAM
    vb.memory = 2048
    # Tweak the number of processors below
    vb.cpus = 2
    # Create link of virtualbox with host folder, vagrant-vbguest plugin are required
    config.vm.synced_folder ".", "/vagrant", type: "virtualbox"
    config.vm.synced_folder "../data", "/data", type: "virtualbox"
    # Get IP of vm booted from virtualbox
    config.hostmanager.ip_resolver = proc do |vm, resolving_vm|
        `"C:\\Program Files\\Oracle\\VirtualBox\\VBoxManage.exe" guestproperty get #{} "/VirtualBox/GuestInfo/Net/1/V4/IP"`.split()[1]

    config.hostmanager.enabled = true
    config.hostmanager.manage_host = true
    config.hostmanager.ignore_private_ip = false
    config.hostmanager.include_offline = true
    config.hostmanager.aliases = ["dockerized-ubuntu-vm.local"]
  # post script to update, ubuntu, install python, ansible and boto
  config.vm.provision :shell, :path => ""
  config.vm.provision :shell, :path => ""
  config.vm.provision :shell, :path => ""
  config.vm.provision :shell, :path => ""
end file contents

apt-get update -y

apt-get upgrade -y

apt-get install -y vim telnet dos2unix git zip unzip file contents

sudo apt-get update -y

sudo apt-get install -y python3-pip

python3 -m pip install pipx file contents

sudo pip3 install ansible file contents

pip3 install boto

pip3 install boto3

pip3 install --upgrade awscli

Once the files are ready, open a command prompt at the directory which contains the Vagrantfile, then type “vagrant up”.

After the “vagrant up” is completed, type “vagrant ssh” to access to the shell of the vm.

Finally, configure aws to be usable by the vm, refer to the link Configuration and credential file settings – AWS Command Line Interface ( and search for “aws configure”

To exit into comand prompt “Ctrl+d” . When you are done with vagrant, type “vagrant halt” to stop the VirtualBox vm.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.