Using Vagrant with Sitecore Part 1 – Setup Chocolatey, Vagrant, and VirtualBox

This is part 1 of the series of post that I am doing about Vagrant to aid with Sitecore Development

Part 1 – This post
Part 2 – MongoDB on Linux build using Vagrant
Part 3 – Sitecore using Solr running on Ubuntu Linux

I am always looking at various option to improve my development, and I remember watching a PluraslSight course by Wes Higbee, Introduction to Versioning Environments With Vagrant and I now want to experiment with vagrant, to build virtual boxes to run MongoDB and Solr

As detailed on Wes’s course I will be using https://chocolatey.org/ to install Vagrant, and VirtualBox.

Sidenote I already have VirtualBox and Vagrant installed on my machine, but I am assuming that they where installed manually, as DevOps build my work machine, and it came preloaded with these tools. As Chocolatey makes it easier to run upgrades I wanted to reinstall the tools using Chocolatey, especially as I have read that to use Chocolatey to perform upgrades, the tool has to be installed using Chocolatey.

Note

I have performed all of the following on a machine with 32GB of ram, Intel Xeon processor running Windows 7 Professional. machine, so I have plenty of processing power to run multiple VM’s. Your milage may vary.

Getting Started

I will be running the scripts in an Administrative PowerShell. Check what folder you start in. Because you are running powershell as an administrator it tends to default to the c:\windows\system32 folder. Never a good item to play around in here to switch to your users home directory first.


cd $home

or whatever folder you are going to be creating your Vagrant Images in.

Before starting, verify what the ExecutionPolicy is by running


Get-ExecutionPolicy

By default, it is Restricted.

If you view the documentation on Chocolatey, for PowerShell V3+ , the policy must be at least RemoteSigned. Simple and easy to change, run


Set-ExecutionPolicy -ExecutionPolicy RemoteSigned

Now run the following script, that you copy from Chocolatey Installation Instructions


iwr https://chocolatey.org/install.ps1 -UseBasicParsing | iex

If you get the following



Installing chocolatey on this machine
& : File C:\Users\darrenguy\AppData\Local\Temp\chocolatey\chocInstall\tools\chocolateyInstall.ps1 cannot be loaded because running scripts is disabled on this system. For more
information, see about_Execution_Policies at http://go.microsoft.com/fwlink/?LinkID=135170.
At line:161 char:3
+ & $chocInstallPS1
+ ~~~~~~~~~~~~~~~
+ CategoryInfo : SecurityError: (:) [], PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess
Ensuring chocolatey commands are on the path
Ensuring chocolatey.nupkg is in the lib folder
d---- 07/07/2016 11:39 chocolatey

The execution policy has not been set correctly. Once you correct that, run again, and you should get the following.



Installing chocolatey on this machine
Creating ChocolateyInstall as an environment variable (targeting 'Machine')
Setting ChocolateyInstall to 'C:\ProgramData\chocolatey'
WARNING: It's very likely you will need to close and reopen your shell
before you can use choco.
Restricting write permissions to Administrators
We are setting up the Chocolatey package repository.
The packages themselves go to 'C:\ProgramData\chocolatey\lib'
(i.e. C:\ProgramData\chocolatey\lib\yourPackageName).
A shim file for the command line goes to 'C:\ProgramData\chocolatey\bin'
and points to an executable in 'C:\ProgramData\chocolatey\lib\yourPackageName'.

Creating Chocolatey folders if they do not already exist.

WARNING: You can safely ignore errors related to missing log files when
upgrading from a version of Chocolatey less than 0.9.9.
'Batch file could not be found' is also safe to ignore.
'The system cannot find the file specified' - also safe.
PATH environment variable does not have C:\ProgramData\chocolatey\bin in it. Adding...
Adding Chocolatey to the profile. This will provide tab completion, refreshenv, etc.
WARNING: Chocolatey profile installed. Reload your profile - type . $profile
Chocolatey (choco.exe) is now ready.
You can call choco from anywhere, command line or powershell by typing choco.
Run choco /? for a list of functions.
You may need to shut down and restart powershell and/or consoles
first prior to using choco.
Ensuring chocolatey commands are on the path
Ensuring chocolatey.nupkg is in the lib folder


To install Vagrant, run


choco install Vagrant

You will get a prompt



Installing the following packages:
vagrant
By installing you accept licenses for the packages.

vcredist2010 v10.0.40219.1 [Approved]
The package vcredist2010 wants to run 'chocolateyInstall.ps1'.
Note: If you don't run this script, the installation will fail.
Note: To confirm automatically next time, use '-y' or consider setting
'allowGlobalConfirmation'. Run 'choco feature -h' for more details.
Do you want to run the script?([Y]es/[N]o/[P]rint):

Just enter Y

If you get more prompts to run chocolateyinstall.ps1, just enter Y

Chocolatey will download and install vagrant. Once completed to verify that it has been installed, run


vagrant -v 

Next install VirtualBox


choco install virtualbox -y

This time I added the -y paramter to accept all the prompts

Next Install cygwin


choco install cyg-get -y

After the package has installed, close and start another administrator powershell window so that you can take advantage of the changes to the path

Lastly install rsync. This will be used later to sync files with the host environments


choco install rsync -y

Now in all the demo’s I have seen that start with using vagrant, they use hasicorp/precise32. Why be the same, I used hashicorp/precise64.

From the command prompt run


vagrant init hashicorp/precise64 --minimal

After waiting a bit for the image to be downloaded, then get presented with the following error:

VBoxManage.exe: error: VT-x is disabled in the BIOS for all CPU modes (VERR_VMX_MSR_ALL_VMX_DISABLED)

Turns out that to run virtual 64bit O/S you need to go into the bios. I followed these instructions VT-x is disabled in the BIOS for both all CPU modes (VERR_VMX_MSR_ALL_VMX_DISABLED)

My machine was slightly different

Setting Virtualisation Support via BIOS for 64bit O/S

Setting Virtualisation Support

But with those changes made, ran


vagrant up

And after waiting for a bunch of packages to be downloaded, I have a working copy of Ubuntu running.

For me this is everything I did when I brought the box up



Bringing machine 'default' up with 'virtualbox' provider...
==> default: Checking if box 'hashicorp/precise64' is up to date...
==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
==> default: Forwarding ports...
default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: 127.0.0.1:2222
default: SSH username: vagrant
default: SSH auth method: private key
default:
default: Vagrant insecure key detected. Vagrant will automatically replace
default: this with a newly generated keypair for better security.
default:
default: Inserting generated public key within guest...
default: Removing insecure key from the guest if it's present...
default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Machine booted and ready!
GuestAdditions versions on your host (5.0.24) and guest (4.2.0) do not match.
stdin: is not a tty
Reading package lists...
Building dependency tree...
Reading state information...
The following extra packages will be installed:
fakeroot linux-headers-3.2.0-23 make patch
Suggested packages:
make-doc diffutils-doc
The following NEW packages will be installed:
dkms fakeroot linux-headers-3.2.0-23 linux-headers-3.2.0-23-generic make
patch
0 upgraded, 6 newly installed, 0 to remove and 66 not upgraded.
Need to get 12.7 MB of archives.
After this operation, 68.5 MB of additional disk space will be used.
Get:1 http://us.archive.ubuntu.com/ubuntu/ precise/main make amd64 3.81-8.1ubuntu1 [118 kB]
Get:2 http://us.archive.ubuntu.com/ubuntu/ precise/main patch amd64 2.6.1-3 [80.2 kB]
Get:3 http://us.archive.ubuntu.com/ubuntu/ precise/main dkms all 2.2.0.3-1ubuntu3 [73.1 kB]
Get:4 http://us.archive.ubuntu.com/ubuntu/ precise/main fakeroot amd64 1.18.2-1 [87.2 kB]
Get:5 http://us.archive.ubuntu.com/ubuntu/ precise/main linux-headers-3.2.0-23 all 3.2.0-23.36 [11.4 MB]
Get:6 http://us.archive.ubuntu.com/ubuntu/ precise/main linux-headers-3.2.0-23-generic amd64 3.2.0-23.36 [947 kB]
dpkg-preconfigure: unable to re-open stdin: No such file or directory
Fetched 12.7 MB in 2min 18s (91.7 kB/s)
Selecting previously unselected package make.
(Reading database ... 51095 files and directories currently installed.)
Unpacking make (from .../make_3.81-8.1ubuntu1_amd64.deb) ...
Selecting previously unselected package patch.
Unpacking patch (from .../patch_2.6.1-3_amd64.deb) ...
Selecting previously unselected package dkms.
Unpacking dkms (from .../dkms_2.2.0.3-1ubuntu3_all.deb) ...
Selecting previously unselected package fakeroot.
Unpacking fakeroot (from .../fakeroot_1.18.2-1_amd64.deb) ...
Selecting previously unselected package linux-headers-3.2.0-23.
Unpacking linux-headers-3.2.0-23 (from .../linux-headers-3.2.0-23_3.2.0-23.36_all.deb) ...
Selecting previously unselected package linux-headers-3.2.0-23-generic.
Unpacking linux-headers-3.2.0-23-generic (from .../linux-headers-3.2.0-23-generic_3.2.0-23.36_amd64.deb) ...
Processing triggers for man-db ...
Setting up make (3.81-8.1ubuntu1) ...
Setting up patch (2.6.1-3) ...
Setting up dkms (2.2.0.3-1ubuntu3) ...
Setting up fakeroot (1.18.2-1) ...
update-alternatives: using /usr/bin/fakeroot-sysv to provide /usr/bin/fakeroot (fakeroot) in auto mode.
Setting up linux-headers-3.2.0-23 (3.2.0-23.36) ...
Setting up linux-headers-3.2.0-23-generic (3.2.0-23.36) ...
Examining /etc/kernel/header_postinst.d.
run-parts: executing /etc/kernel/header_postinst.d/dkms 3.2.0-23-generic /boot/vmlinuz-3.2.0-23-generic
Copy iso file C:\Program Files/Oracle/VirtualBox/VBoxGuestAdditions.iso into the box /tmp/VBoxGuestAdditions.iso
stdin: is not a tty
mount: warning: /mnt seems to be mounted read-only.
Installing Virtualbox Guest Additions 5.0.24 - guest version is 4.2.0
stdin: is not a tty
Verifying archive integrity... All good.
Uncompressing VirtualBox 5.0.24 Guest Additions for Linux............
VirtualBox Guest Additions installer
Removing installed version 4.2.0 of VirtualBox Guest Additions...
Copying additional installer modules ...
Installing additional modules ...
Removing existing VirtualBox DKMS kernel modules ...done.
Removing existing VirtualBox non-DKMS kernel modules ...done.
Building the VirtualBox Guest Additions kernel modules ...done.
Doing non-kernel setup of the Guest Additions ...done.
You should restart your guest to make sure the new modules are actually used

stdin: is not a tty
Restarting VM to apply changes...
==> default: Attempting graceful shutdown of VM...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: 127.0.0.1:2222
default: SSH username: vagrant
default: SSH auth method: private key
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
==> default: Mounting shared folders...
default: /vagrant => D:/VirtualBoxVMs/ubuntu64

And to quickly connect to the VM, execute


vagrant ssh


Welcome to Ubuntu 12.04 LTS (GNU/Linux 3.2.0-23-generic x86_64)

* Documentation: https://help.ubuntu.com/
New release '14.04.4 LTS' available.
Run 'do-release-upgrade' to upgrade to it.

Welcome to your Vagrant-built virtual machine.
Last login: Fri Sep 14 06:23:18 2012 from 10.0.2.2
vagrant@precise64:~$

To exit of from the SSH terminal, Ctrl-C

Another way to check, is to issue the following command


vboxmanage list runningvms

This shows



"ubuntu64_default_1467971257293_6276" {a2b0cafc-c434-47af-98b0-e1c7b83b1d03}

A few other commands that can be executed are

  • vagrant status
  • Just make sure you are in the correct folder

  • vagrant global-status
  • vboxmanage list vms

Next Steps

Now that I have got Vagrant working, the next steps are to get MongoDB installed.

According to knowledge base article https://kb.sitecore.net/articles/920798,

Sitecore versions 7.5 Initial Release through 8.0 Update-4 are recommended for usage only with the MongoDB 2.6

I will be using MongoDB 2.6.x when I start configuring my MongoDB’s for development

Advertisement
About

My musing about anything and everything

Tagged with: , , , , , , ,
Posted in MongoDB, PowerShell, Sitecore, Vagrant, VirtualBox
2 comments on “Using Vagrant with Sitecore Part 1 – Setup Chocolatey, Vagrant, and VirtualBox
  1. ferventcoder says:

    “I have read that to use Chocolatey to perform upgrades, the tool has to be installed using Chocolatey.”

    Not exactly true. To take advantage of “upgrade all”, you just need to have run the choco install.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 13 other subscribers
%d bloggers like this: