search by tags

for the user

adventures into the land of the command line

creating your own vagrant box out of someone elses

I’ve been using this vagrant box:

It’s a centOS-6.7 vm, with python 2.6.6 and ansible installed. It’s great but there were a few little things I found myself changing everytime I created a new dev environment with this box, before starting any work.

I’d want to disable selinux, install python 2.7 and install pip. Wouldn’t it be great if these things were already there? So I followed some blogs here and here.

Step one, choose a box. As I mentioned I’m using maurofelipe/centOS-6.7-x86_64

Start it up.

[[email protected] ~]$ mkdir base
[[email protected] ~]$ cd base
[[email protected] ~/base]$ vagrant init maurofelipe/centOS-6.7-x86_64
[[email protected] ~/base]$ vagrant up --provider=virtualbox

Step one.five is to potentially disable the USB port for this vm in virtualbox. If you don’t have the virtual box guest additions installed, some things like the USB port won’t work. You have to turn it off in the vm’s settings in virtualbox.

Step two is to disable selinux.

[[email protected] ~/base]$ vagrant up
[[email protected] ~/base]$ vagrant ssh
[[email protected] ~]$ sudo su -
[[email protected] ~]# vim /etc/selinux/config

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
# SELINUXTYPE= can take one of these two values:
#     targeted - Targeted processes are protected,
#     mls - Multi Level Security protection.

[[email protected] ~]# exit
[[email protected] ~]$ exit
[[email protected] ~/base]$ vagrant reload

Step three, install python2.7 and pip

[[email protected] ~/base]$ vagrant ssh
[[email protected] ~]$ sudo su -
[[email protected] ~]# yum update -y
[[email protected] ~]# yum groupinstall "Development tools" -y
[[email protected] ~]# yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel -y
[[email protected] ~]# wget
[[email protected] ~]# tar xf Python-2.7.11.tar.xz
[[email protected] ~]# cd Python-2.7.11
[[email protected] ~/Python-2.7.11]# ./configure --prefix=/usr/local --enable-unicode=ucs4 --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"
[[email protected] ~/Python-2.7.11]# make && make altinstall
[[email protected] ~/Python-2.7.11]# cd ../
[[email protected] ~]# wget
[[email protected] ~]# python2.7
[[email protected] ~]# easy_install-2.7 pip

Step four, clean up after youself.

[[email protected] ~]# rm -rf Python*
[[email protected] ~]# rm -f ez_setup
[[email protected] ~]# yum clean all
[[email protected] ~]# cat /dev/null > ~/.bash_history && history -c && exit
[[email protected] ~]$ cat /dev/null > ~/.bash_history && history -c && exit

Step five, create the box.

[[email protected] ~/base]$ vagrant package --output
==> base: Attempting graceful shutdown of VM...
==> base: Clearing any previously set forwarded ports...
==> base: Exporting VM...
==> base: Compressing package to: ~/base/

Step six, add the box to your vagrant install.

[[email protected] ~/base]$ vagrant box list
maurofelipe/centOS-6.7-x86_64   (virtualbox, 1.0.0)

[[email protected] ~/base]$ vagrant box add centOS-6.7-x86_64-python2.7-ansible
==> box: Adding box 'centOS-6.7-x86_64-python2.7-ansible' (v0) for provider:
    box: Downloading: file:///~/base/
==> box: Successfully added box 'centOS-6.7-x86_64-python2.7-ansible' (v0) for 'virtualbox'!

[[email protected] ~/base]$ vagrant box list
centOS-6.7-x86_64-python2.7-ansible (virtualbox, 0)
maurofelipe/centOS-6.7-x86_64       (virtualbox, 1.0.0)

In the vagrant box add command, the first argument is some name you want to make up for your box. The second argument is the name of the actual .box file. The name you make up is the value that you would put into in your Vagrantfile.

Step seven, try out your new awesome box!

[[email protected] ~/base]$ vagrant halt
[[email protected] ~/base]$ vagrant destroy
[[email protected] ~/base]$ rm -f Vagrantfile
[[email protected] ~/base]$ vagrant init centOS-6.7-x86_64-python2.7-ansible
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`` for more information on using Vagrant.
[[email protected] ~/base]$ vagrant up
[[email protected] ~/base]$ vagrant ssh