This is the multi-page printable view of this section. Click here to print.

Return to the regular view of this page.

Vagrant

1 - Vagrant on Windows

1. Overview

Important
This documentation describes the installation of the required tools for ansible-oracle on a Windows based hostsystem.
chocolatey
  • Requirements

    • Intel/AMD x86 CPU is mandatory
      no support for Mac with M1

    • 16 GB RAM

    • 150 GB free Disk space
      The free space is needed in your home directory in Windows.

    • Admin privileges on Host machine

    • Hyper-V disabled

    • no WSL/WSL2 for installation
      While you may try it, the documentation states that Hyper-V should be completely disabled and that no WSL/WSL2 is used.

Warning
There are many issues when Hyper-V is active on the host machine.
Please switch Hyper-V off completely, before starting the boxes with Vagrant.
If you do find a really good working solution with Vagrant + VirtualBox and Hyper-V, feedback is welcome.

2. Installation

2.1. Disable Hyper-V in Windows

Warning
There are numerous problems with Vagrant & VirtualBox when Hyper-V is enabled.
It is therefore recommended to disable it for ansible-oracle.
Important
All commands require a cmd.exe with admin rights.
Check setting of Hyper-V
bcdedit

The output should contain a line with hypervisorlaunchtype.
If the line is not shown or Off, Hyper-V is completely disabled.

Output
# bcdedit

Windows-Start-Manager
---------------------
...

Windows-Startladeprogramm
-------------------------
...
hypervisorlaunchtype    Off

If it is Auto or On

Disable Hyper-V with immediate reboot
bcdedit /set {current} hypervisorlaunchtype off
shutdown -r -t 0

2.2. Chocolatey

Important
The installation of Chocolatey is not mandatory for ansible-oracle.
All tools could be installed manually. Please ensure, that they are all executable from git+bash.
It is highly recommended to use Chocolatey with ansible-oracle.
Important
See the Homepage of chocolatey for more details.
Execute in PowerShell with Admin rights
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))

2.3. git+bash, VirutalBox and Vagrant

Execute in cmd.exe with admin rights
choco install git vagrant virtualbox

2.4. ConEmu - Handy Windows Terminal

Important
This step is optional.

This is a really good alternative terminal to cmd.exe for windows.
It is not recommended for ansible-oracle but you should give it a try and enjoy it - especially when VSCode is not used.

Execute in cmd.exe with admin rights
choco install conemu

2.5. Visual Studio Code

Important
This step is optional.
You should use VSCode - especially when Advanced or Expert setups are planned for a later time.
Execute in cmd.exe with admin rights
choco install vscode.install

3. Configuration

3.1. SSH-Setup

Warning
The example expects the private key at the default location.
Important
Create a custom key and place the public key in same directory as the Vagrantfile. Do not use the created keys from Vagrant.
You should always use the ssh-agent to connect to all machines.
Important
All commands are executed in git+bash on the Host machine - not inside a VM!
Create a key when needed
ssh-keygen
Output
ssh-keygen

Generating public/private rsa key pair.

Enter file in which to save the key (/c/Users/User/.ssh/id_rsa): Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/User/.ssh/id_rsa
Your public key has been saved in /c/Users/User/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:Xq9EGKMUEXFkxeli4NilfvwEkOAmvkV1PiRteA+NQRQ ubuntu@ansible-oracle-bastion
Important
Enable Agent Forwarding for all SSH-Sessions.
This is mandatory for Visual Studio Code.
Enable Agent Forwarding for all SSH-Sessions.
code ~/.ssh/config

Host *
  ForwardAgent yes
Start a ssh-agent (bash)
eval $(ssh-agent)
Output
eval $(ssh-agent)
Agent pid 16840
Import a key
ssh-add ~/.ssh/id_rsa
Output
$ ssh-add ~/.ssh/id_rsa
Identity added: /c/Users/User/.ssh/id_rsa (User@unknown)
Show imported keys
ssh-add -l
Output
ssh-add -l
2048 SHA256:EsVIFzfCLUDTO2cMTf4q4qt2Eu0w1pA2sdcXxh9jyBs User@unknown (RSA)

3.2. Vagrant SSH-Setup

Important
The Vagrantfile has a provisioner script block which copy a stored id_rsa.pub into authorized_keys on the target machine.

The exact command to copy the key is shown during the deployment description.

3.3. Vagrant Plugins

The following modules are used by the tutorial examples.

  • install* vagrant-disksize
    This is an experimental plugin which is needed to resize the 1. disk of a vagrant box.

vagrant plugin install vagrant-disksize

4. See also

2 - Vagrant Basics

What is vagrant?

Vagrant is a tool that makes it EASIER and FASTER to setup virtual machines. Vagrant Boxes are pre-built base images (e.g. Oracle Linux) that can be imported into Vagrant as a starting point. For our use-case, we will use Vagrant together with Virtualbox and Oracle Linux

Installation

  1. Download and install Vagrant
  2. Download and install Oracle Virtualbox

Let’s start

Using Tim Halls’s guide, let’s play https://oracle-base.com/articles/vm/vagrant-a-beginners-guide

  1. hmm, cannot download that first OL box, let’s see the oracle doc https://yum.oracle.com/boxes/
  2. Note also that the default provider for vagrant has changed to libvirt (was virtualbox), so we will need to add “–provider virtualbox” to our vagrant add commands

Download Vagrant boxes

  • Instead of downloading a large DVD image, we can download a small vagrant box.
  • We can manually download a new box using the vagrant box add command.
  • We only need to do this once for each vagrant box (e.g. one time for Oracle Linux 7 and one time for Oracle Linux 8).
  • This download process would also happen automatically if required, when you reference a new box in a Vagrantfile

In a DOS command prompt…

vagrant box add --provider virtualbox https://oracle.github.io/vagrant-projects/boxes/oraclelinux/7.json
vagrant box add --provider virtualbox https://oracle.github.io/vagrant-projects/boxes/oraclelinux/8.json

Some vagrant addons

  1. allows us to resize disks (optional)

In a DOS command prompt…

vagrant plugin install vagrant-disksize
  1. ensure the virtualbox guest additions is updated, required to ensure that the guest additions are automatically updated for all new vagrant boxes

In a DOS command prompt…

vagrant plugin install vagrant-vbguest
  1. Automatically update the /etc/hosts

In a DOS command prompt…

vagrant plugin install vagrant-hostsupdater

Create the initial vagrantfile

To create the virtual machine, we first of all create a new directory, change to it and create the initial “vagrantfile”

In a DOS command prompt…

mkdir D:\vagrant\vol7db19
cd /D D:\vagrant\vol7db19
vagrant init

Start the VM

edit the vagrantfile (see Tim Hall’s website above) and when ready with our configuration, we can install, create and start the VM with the following command…

In a DOS command prompt…

vagrant up

Changing the vagrantfile

if you change the vagrantfile, destroy and recreate your virtual machine

In a DOS command prompt…

vagrant destroy -f
vagrant up

accessing the VM

  1. use the command “vagrant ssh” to access the VM per shh in your DOS command prompt
  2. or connect with ssh to 127.0.0.1, port 2222 with your favourite tool

Removing Vagrant boxes

  • We can remove any old boxes we are no longer using, with the vagrant box remove command.
  • These boxes will be automatically downloaded again if required.
  • It is best not to remove them, if still used regularly, as it takes a few minutes to download them

In a DOS command prompt…

vagrant box remove oraclelinux/7
vagrant box remove oraclelinux/8