Vagrant & Puppet
Russ McKendrick · 4 min read ·
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
Related terms: AgentAgent SkillsAmazon Web ServicesAnsibleAutomationAzure DevOps
More from the archive
First Steps with Ansible
Explore Ansible for AWS automation, transitioning from manual scripting. Initiate playbook for VPC and ELB deployment.
3 min read

More Puppet
Efficient Puppet setup on CentOS with quick deployment scripts for Puppet Master and Agents, including a GitHub repo for easy configuration management.
1 min read

Comments
