Note! If you are trying the examples yourself, note that especially running them the first time may take several minutes. Running vagrant box add centos/7
well in advance may cut a lot of time, as you don’t have to download the image later on.
Installation, by not using the downloadable packets:
Note! You can get the newest Vagrant installable from https://www.vagrantup.com/downloads.html
sudo cd /etc/yum.repos.d/
sudo wget http://download.virtualbox.org/virtualbox/rpm/rhel/virtualbox.repo
sudo yum search virtualbox
sudo yum install VirtualBox-5.1
cd
wget https://releases.hashicorp.com/vagrant/1.9.1/vagrant_1.9.1_x86_64.rpm
sudo yum install vagrant_1.9.1_x86_64.rpm
sudo /sbin/rcvboxdrv setup
Note: the versions for VirtualBox and Vagrant differ Note: if you are using Fedora, change /rhel/ to /fedora/ in the link above
Installation on Ubuntu/Debian by not using the installation packages:
sudo apt-get install dkms
sudo apt-get install virtualbox
sudo apt-get install vagrant
To verify installation, run:
vagrant version
The vagrant box is built by the configuration in a file called Vagrantfile. It uses Ruby syntax, but it can be easily modified without any knowledge of the programming language. To test the example box first clone the file with:
git clone https://github.com/coderefinery/tools.git
To add the box, run:
vagrant box add centos/7
Choose the provider you want to use, in this example it is virtualbox
Change to the cloned directory (vagrant-basic) and run:
vagrant up
After the server is built, you can access it with command
vagrant ssh
executed from the directory containing the Vagrantfile. You can also ssh the machine normally with ssh client, the vagrant user’s default password is vagrant. If the script was executed correctly, you should also see httpd server responding via a forwarded port, from address http://127.0.0.1:7888.
Other common commands for Vagrant are:
vagrant halt
vagrant destroy
vagrant up --provision
to stop, delete and reprovision a virtual machine, respectively. To create a Vagrantfile from scratch or to update an existing box, use commands:
vagrant init <box name>
vagrant box update
Excercise:
vagrant up
vagrant rsync-auto
To make the shared folder work without using rsync, you will need the VirtualBox Guest Additions installed. Guest additions provide several features for virtual machines, for example drivers. This example shows how to install these on VirtualBox 5.1.2. Normally you won’t need this but in case you do, it is good to know about this package.
wget http://download.virtualbox.org/virtualbox/5.1.2/VBoxGuestAdditions_5.1.2.iso
sudo mkdir /media/VBoxGuestAdditions
sudo mount -o loop,ro VBoxGuestAdditions_5.1.2.iso /media/VBoxGuestAdditions
sudo sh /media/VBoxGuestAdditions/VBoxLinuxAdditions.run
rm VBoxGuestAdditions_5.1.2.iso
sudo umount /media/VBoxGuestAdditions
sudo rmdir /media/VBoxGuestAdditions
Get started with Puppet: https://www.digitalocean.com/community/tutorials/getting-started-with-puppet-code-manifests-and-modules
You can find a Vagrant example that configures the server with Ansible under https://github.com/coderefinery/tools.git, the advanced directory. This example requires that Ansible is installed in the host machine. Some of the modules used will require more recent versions of Ansible, like version 2.X.
Note: Ansible, like many other DevOps tools, tends to change quite a lot from version to version. Thus some features may not work with older versions, sometimes even the folder structure changes.
Excercise:
vagrant up
Public Docker images available in Docker hub https://hub.docker.com/ but a word of warning: not all images can be trusted! There have been examples of contaminated images so investigate before using images blindly.
In this excercise you can use the Vagrant repository again, use the directory ‘docker’. The Vagrantfile will again install Centos 7, but now with Docker and it will also start a docker image “jupyter/minimal-notebook”. In Docker hub this image can be found behind url https://hub.docker.com/r/jupyter/minimal-notebook/ and in GitHub under https://github.com/jupyter/docker-stacks.
This Vagrantfile will first install Docker with:
yum install docker
After this it will start the Docker daemon, which is the persistent process managing the containers. The jupyter image will be pulled and started with command:
docker run -d -p 8888:8888 jupyter/minimal-notebook
The notebook should be accessible behind url http://127.0.0.1:8080 if everything went as expected (there is a redirect in Vagrantfile from port 8888 of guest machine to 8080 on host machine. You can also vagrant ssh
to the guest machine. You can now also access the container from shell. Find the container name (or id) with:
docker ps
Now you can execute shell in container with:
docker exec -it <id> bash
--provision
. You could add a startup script. Information about systemd startup scripts in https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/System_Administrators_Guide/sect-Managing_Services_with_systemd-Unit_Files.htmlVagrant, Ansible, Puppet, Chef, Docker, LXC