Vagrant allows developers to bring up local development machines in a controlled method using pre-built configuration files called boxes. Once a box has been installed on the developers local machine it can be powered on with the following command;
vagrant upWhen the box is brought up it automatically provisions itself using a number of provisioners including Puppet, this means that the production deployment scripts can also be run on local development copies of the instances. The instances on the local machines are powered by Virtualbox and there Windows, Linux and Mac versions of Vagrant.
Once a local instance has booted it can attach a folder on the developers local machine to the virtual server, this means that a developer can work on a local copy of the code within their chosen IDE and be able to test the code instantly on an environment which matches the production environment as closely as possible, all without the need to deploy multiple servers within a hosting environment.
A typical Vagrant session looks like the following;
russ$ vagrant upBringing machine ādefaultā up with āvirtualboxā providerā¦[default] Importing base box āCentOS-Dev-6.5āā¦[default] Matching MAC address for NAT networkingā¦[default] Setting the name of the VMā¦[default] Clearing any previously set forwarded portsā¦[default] Creating shared folders metadataā¦[default] Clearing any previously set network interfacesā¦[default] Preparing network interfaces based on configurationā¦[default] Forwarding portsā¦[default] - 22 => 2222 (adapter 1)[default] - 80 => 8888 (adapter 1)[default] Booting VMā¦[default] Waiting for machine to boot. This may take a few minutesā¦[default] Machine booted and ready![default] Setting hostnameā¦[default] Configuring and enabling network interfacesā¦[default] Mounting shared foldersā¦[default] - /data[default] - /vagrant[default] - /webroot[default] - /tmp/vagrant-puppet/manifests[default] - /tmp/vagrant-puppet/modules-0[default] Running provisioner: puppetā¦Running Puppet with vagrant.ppā¦Warning: Config file /etc/puppet/hiera.yaml not found, using Hiera defaultsNotice: Compiled catalog for dev.local in environment production in 2.30 secondsNotice: /Stage[main]/Common::Apps/Package[tree]/ensure: createdNotice: /Stage[main]/Mysql::Client::Install/Package[mysql_client]/ensure: createdNotice: /Stage[main]/Common::Repos/Package[epel-release-6ā8.noarch]/ensure: createdNotice: /Stage[main]/Common::Apps/Package[man]/ensure: createdNotice: /Stage[main]/Common::Apps/Package[dstat]/ensure: createdNotice: /Stage[main]/Common::Apps/Package[mailx]/ensure: createdNotice: /Stage[main]/Common::Apps/Package[lsof]/ensure: createdNotice: /Stage[main]/Services::Apache/Package[httpd-devel]/ensure: createdNotice: /Stage[main]/Mysql::Server::Install/Package[mysql-server]/ensure: createdNotice: /Stage[main]/Mysql::Server::Config/File[/etc/mysql]/ensure: createdNotice: /Stage[main]/Mysql::Server::Config/File[/etc/my.cnf]/content: content changed ā{md5}8ace886bbe7e274448bc8bea16d3ead6ā to ā{md5}7bbc1d3914d13dd7960d5fa5bc5a80c6āNotice: /Stage[main]/Ntp::Install/Package[ntp]/ensure: createdNotice: /Stage[main]/Ntp::Config/File[/etc/ntp.conf]/content: content changed ā{md5}7fda24f62b1c7ae951db0f746dc6e0ccā to ā{md5}2396e8417e644318c99399b0460d93ebāNotice: /Stage[main]/Services::Phpmyadmin/Package[phpMyAdmin]/ensure: createdNotice: /Stage[main]/Services::Phpmyadmin/File[/etc/phpMyAdmin/config.inc.php]/content: content changed ā{md5}cc6db4fb4e08b40c637fa096e55f4bd5ā to ā{md5}ad2fd178c0bbd0061196a3a3bc24af19āNotice: /Stage[main]/Ntp::Service/Service[ntp]/ensure: ensure changed āstoppedā to ārunningāNotice: /Stage[main]/Services::Apache/File[/etc/httpd/conf.d/vhost.conf]/ensure: createdNotice: /Stage[main]/Services::Php/Package[php-pecl-apc]/ensure: createdNotice: /Stage[main]/Services::Php/Package[php-devel]/ensure: createdNotice: /Stage[main]/Services::Php/Package[php-soap]/ensure: createdNotice: /Stage[main]/Services::Php/Package[php-ldap]/ensure: createdNotice: /Stage[main]/Git::Install/Package[git]/ensure: createdNotice: /Stage[main]/Git::Install/Package[git-svn]/ensure: createdNotice: /Stage[main]/Mysql::Server::Config/File[/etc/mysql/conf.d]/ensure: createdNotice: /Stage[main]/Mysql::Server::Service/Service[mysqld]/ensure: ensure changed āstoppedā to ārunningāNotice: /Stage[main]/Mysql::Server::Root_password/Mysql_user[root@localhost]/password_hash: defined āpassword_hashā as ā*EA791BBC44F8413FFF8C3E939FE24752D4E84FC7āNotice: /Stage[main]/Mysql::Server::Root_password/File[/root/.my.cnf]/ensure: defined content as ā{md5}67b81309e1920b5a39c836c83b455316āNotice: /Stage[main]/Services::Mysqldatabase/Mysql::Db[vagrant]/Mysql_database[vagrant]/ensure: createdNotice: /Stage[main]/Services::Mysqldatabase/Mysql::Db[vagrant]/Mysql_user[vagrant@localhost]/ensure: createdNotice: /Stage[main]/Services::Mysqldatabase/Mysql::Db[vagrant]/Mysql_grant[vagrant@localhost/vagrant.*]/ensure: createdNotice: /Stage[main]/Services::Phpmyadmin/File[/etc/httpd/conf.d/phpMyAdmin.conf]/content: content changed ā{md5}b6653d976dbab702b2bec270adc4b6f4ā to ā{md5}d0c590e1018012bd33cd9fa74f5d28bcāNotice: /Stage[main]/Services::Apache/Service[httpd]/ensure: ensure changed āstoppedā to ārunningāNotice: /Stage[main]/Services::Apache/File[/webroot/public_html]/ensure: createdNotice: /Stage[main]/Services::Git/Git::Repo[vagrant-dev-box]/Exec[git_repo_vagrant-dev-box]/returns: executed successfullyNotice: /Stage[main]/Services::Php/Package[php-xml]/ensure: createdNotice: Finished catalog run in 260.98 secondsThis brings up a CentOS server, port maps port 8888 on the local machine to port 80 on the instance and then mounts ~/Documents/Vagrant/apache/webroot/ as /webroot on the instance. Once the instance has booted it then executes a Puppet manifest which installs & configures the following services;
- Apache
- PHP
- MySQL
- PHPMyAdmin
- Also as other tools such as VIM etc are installed
Once installed it checks out code from a Github repository into /webroot ready for coding to start, the code is also available in the local browser at http://localhost:8888/.
Once the instance has been finished with you can remove it or power it down ready to use again, neither of these actions will remove the code or GIT configuration from the local copy in the ~/Documents/Vagrant/apache/webroot/ directory.
Vagrant is an Open Source project released under the MIT license and can be found here
For my own Vagrant configuration check my GitHub repo



