{"id":253,"date":"2014-06-11T16:57:00","date_gmt":"2014-06-11T16:57:00","guid":{"rendered":"https:\/\/questy.org\/?p=253"},"modified":"2024-09-26T19:06:33","modified_gmt":"2024-09-26T19:06:33","slug":"the-toolbox-grows","status":"publish","type":"post","link":"https:\/\/questy.org\/index.php\/2014\/06\/11\/the-toolbox-grows\/","title":{"rendered":"The Toolbox Grows&#8230;"},"content":{"rendered":"\n<p>So far we\u2019ve gotten our heads around some important things. &nbsp;First and foremost, vim. &nbsp;Our editor and companion for creating great code and ways to see our code in action and be able to determine at a glance whether our syntax is correct. &nbsp;Also, we\u2019ve looked at revision control. &nbsp;The single largest \u201cCYA\u201d ohmygodimgladivegotanoldercopytorestoreto sort of paradigm where you can roll yourself back to previously \u201cknown good\u201d revisions to save that day\u2026besides that, it\u2019s just darned good practice to keep your code externally saved, revision controlled, and accessible.<\/p>\n\n\n\n<p>I\u2019ve also talked about importance of workflow clarity and quality. &nbsp;If you implement a poor workflow, you just have an automated&nbsp;<em>poor&nbsp;<\/em>workflow. Key word here is \u201cpoor\u201d.<\/p>\n\n\n\n<p>Next up on our browse through the \u201ctoolbox\u201d is \u201cVagrant\u201d. &nbsp;What is this Vagrant, you ask?<\/p>\n\n\n\n<p>Virtualization is paramount in today\u2019s world in a number of ways and for a number of reasons. &nbsp;For extending your server farms to handle even more application expression, to expand your own desktop machines to test\/try different operating systems, and even just rolling up an ad-hoc VM so you can try something without touching a \u201creal\u201d machine in your environment.<\/p>\n\n\n\n<p>Some may disagree, but I\u2019ve found virtualization to be one of the most powerful tools added to the toolbox in years. &nbsp;Not only can you prototype systems or applications, but you can prototype entire environments. &nbsp;This is where Vagrant shines, and especially in the context of Puppet (master + clients), allows you to create a fully functioning Puppet environment upon which to develop, prototype, and test without ever jeopardizing even the least important system of your infrastructure. &nbsp;I count that as a \u201cwin\u201d. &nbsp;Let\u2019s see what this tool can do.<\/p>\n\n\n\n<p><em><strong>What&nbsp;<em>is<\/em>&nbsp;Vagrant?<\/strong><\/em><\/p>\n\n\n\n<p>According to its website:<\/p>\n\n\n\n<p>Vagrant provides easy to configure, reproducible, and portable work environments built on top of industry-standard technology and controlled by a single consistent workflow to help maximize the productivity and flexibility of you and your team.<\/p>\n\n\n\n<p>To achieve its magic, Vagrant stands on the shoulders of giants. Machines are provisioned on top of VirtualBox, VMware, AWS, or any other provider. Then, industry-standard provisioning tools such as shell scripts, Chef, or Puppet, can be used to automatically install and configure software on the machine.<\/p>\n\n\n\n<p>There\u2019s a lot there, but it\u2019s just a fancy way of saying exactly what I said before. &nbsp;Vagrant is essentially a framework system that wraps your virtualization engine to manage&nbsp;<em>environments&nbsp;<\/em>of VMs. &nbsp;Here is where Vagrant will hold the power for us.<\/p>\n\n\n\n<p><em><strong>Virtualization<\/strong><\/em><\/p>\n\n\n\n<p>If Vagrant is the framework, then Virtualization is the foundation. &nbsp;Now, I\u2019ve chosen to use \u201cVirtualbox\u201d for my virtualization technology, but VMWare works every bit as well. &nbsp;I am doing all my testing over Virtualbox, however, so YMMV. &nbsp;Virtualbox is freely available from oracle, and you can download the appropriate version from Virtualbox at&nbsp;<a href=\"https:\/\/www.virtualbox.org.\">https:\/\/www.virtualbox.org.<\/a>&nbsp;&nbsp;I am running the latest version at 4.3.12 (as of this writing) and it serves the Vagrant system extremely well.<\/p>\n\n\n\n<p><em><strong>Vagrant<\/strong><\/em><\/p>\n\n\n\n<p>Next, you\u2019ll need to install Vagrant on your system. &nbsp;You can find all the right packages at&nbsp;<a href=\"http:\/\/www.vagrantup.com.\">http:\/\/www.vagrantup.com.<\/a>&nbsp;&nbsp;I am currently running version 1.6.3 without errors.<\/p>\n\n\n\n<p>[warning]I want to make a disclaimer here since I\u2019ve had an issue or two with Vagrant on a platform I don\u2019t use-Windows. &nbsp;I am a Mac &amp; Linux user, and have had no issues using the Vagrant\/Virtualbox combo on either of these. &nbsp;However, literally every time I\u2019ve used Vagrant over Windows, it\u2019s just been a mess. &nbsp;I\u2019ve known one person (ONE!) who has gotten Vagrant to work over Windows, and it required his getting into the product, editing code, etc. &nbsp;As such, I wouldn\u2019t recommend it for those new to the platform.[\/warning]<\/p>\n\n\n\n<p>On the Mac platform, you get a .dmg file and can extract it run the installer. &nbsp;Linux versions are available as RPM installs and Debian Packages. &nbsp;Once you\u2019re installed, let\u2019s mess around a bit with Vagrant to see what we can do.<\/p>\n\n\n\n<p><em><strong>Getting Started<\/strong><\/em><\/p>\n\n\n\n<p>Vagrant is a unique tool in that it allows you to manage all these varied VMs, but adds a twist. &nbsp;The big twist is that you don\u2019t have to have the&nbsp;<em>source&nbsp;<\/em>materials for the VMs you\u2019re installing. &nbsp;In fact, the simplicity of turning up a new VM is astounding. &nbsp;Take the following series of commands:<\/p>\n\n\n\n<p>cd&nbsp;<br>mkdir precise32<br>cd precise32<br>vagrant init hashicorp\/precise32<br>vagrant up<\/p>\n\n\n\n<p>If your Vagrant is installed correctly, a number of things start to happen. &nbsp;First, Vagrant places a file in your cwd called \u201cVagrantfile\u201d. &nbsp;Your vagrant file (indie) looks like this:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td>-*- mode: ruby -*-<br>vi: set ft=ruby :<br>All Vagrant configuration is done below. The &#8220;2&#8221; in Vagrant.configure<br>configures the configuration version (we support older styles for<br>backwards compatibility). Please don&#8217;t change it unless you know what<br>you&#8217;re doing.<br>Vagrant.configure(&#8220;2&#8221;) do |config|<br># The most common configuration options are documented and commented below.<br># For a complete reference, please see the online documentation at<br># https:\/\/docs.vagrantup.com.<br># Every Vagrant development environment requires a box. You can search for<br># boxes at https:\/\/atlas.hashicorp.com\/search.<br>config.vm.box = &#8220;hashicorp\/precise32&#8221;<br># Disable automatic box update checking. If you disable this, then<br># boxes will only be checked for updates when the user runs<br># <code>vagrant box outdated<\/code>. This is not recommended.<br># config.vm.box_check_update = false<br># Create a forwarded port mapping which allows access to a specific port<br># within the machine from a port on the host machine. In the example below,<br># accessing &#8220;localhost:8080&#8221; will access port 80 on the guest machine.<br># config.vm.network &#8220;forwarded_port&#8221;, guest: 80, host: 8080<br># Create a private network, which allows host-only access to the machine<br># using a specific IP.<br># config.vm.network &#8220;private_network&#8221;, ip: &#8220;192.168.33.10&#8221;<br># Create a public network, which generally matched to bridged network.<br># Bridged networks make the machine appear as another physical device on<br># your network.<br># config.vm.network &#8220;public_network&#8221;<br># Share an additional folder to the guest VM. The first argument is<br># the path on the host to the actual folder. The second argument is<br># the path on the guest to mount the folder. And the optional third<br># argument is a set of non-required options.<br># config.vm.synced_folder &#8220;..\/data&#8221;, &#8220;\/vagrant_data&#8221;<br># Provider-specific configuration so you can fine-tune various<br># backing providers for Vagrant. These expose provider-specific options.<br># Example for VirtualBox:<br>#<br># config.vm.provider &#8220;virtualbox&#8221; do |vb|<br># # Display the VirtualBox GUI when booting the machine<br># vb.gui = true<br>#<br># # Customize the amount of memory on the VM:<br># vb.memory = &#8220;1024&#8221;<br># end<br>#<br># View the documentation for the provider you are using for more<br># information on available options.<br># Define a Vagrant Push strategy for pushing to Atlas. Other push strategies<br># such as FTP and Heroku are also available. See the documentation at<br># https:\/\/docs.vagrantup.com\/v2\/push\/atlas.html for more information.<br># config.push.define &#8220;atlas&#8221; do |push|<br># push.app = &#8220;YOUR_ATLAS_USERNAME\/YOUR_APPLICATION_NAME&#8221;<br># end<br># Enable provisioning with a shell script. Additional provisioners such as<br># Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the<br># documentation for more information about their specific syntax and use.<br># config.vm.provision &#8220;shell&#8221;, inline: &lt;&lt;-SHELL<br># apt-get update<br># apt-get install -y apache2<br># SHELL<br>end<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Note that this is a long file with a lot of explanatory documentation. &nbsp;In actuality, the most important part of your Vagrantfile can be summed up here:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td># -*- mode: ruby -*-\u00a0<br># vi: set ft=ruby :<br>Vagrant.configure(&#8220;2&#8221;) do |config|<br>\u00a0 config.vm.box = &#8220;hashicorp\/precise32&#8221;\u00a0<br>end<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>These are the lines that are uncommented plus the top two declaratives that tell Vagrant what to do. &nbsp;It\u2019s a very simple file that does some very powerful things. &nbsp;First, it checks your home directory in the ~\/.vagrant.d location to see if you already have the \u201cprecise32\u201d Vagrant source \u201cbox\u201d. &nbsp;(more on boxes later). &nbsp;Next, if you do have this, it will simply start up a VM in your virtualization of choice with a randomized name. &nbsp;For instance, mine is called \u201cprecise32_default_1402504453444_30545\u201d. &nbsp;Vagrant takes away the selection of an .iso image, connecting it to the virtual CD\/DVD Rom, starting an installer, etc. &nbsp;It simply sends you a pre-rolled image, places it in your .vagrant.d directory, and provisions the VM to respond to Vagrant commands, and starts it up within Virtualbox. &nbsp;Precise32 is simply a test scenario, as Vagrant\u2019s site has quite a number of varied and specially configured \u201cbox\u201d files that you can use to prototype on at their \u201cready-made\u201d box discovery site:&nbsp;<a href=\"https:\/\/vagrantcloud.com\/discover\/featured.\">https:\/\/vagrantcloud.com\/discover\/featured.<\/a>&nbsp;&nbsp;You can install boxes with too many variations and differentiations to enumerate here, and that\u2019s not really the point for our purposes\u2026 you may find these of great assistance in your own workplace, but let\u2019s continue.<\/p>\n\n\n\n<p>When you run your \u201cvagrant init\u201d command listed above, it places a Vagrantfile, and when you do a \u201cvagrant up\u201d, it automatically retrieves your box file, provisions, and starts the VM. &nbsp;Now, by simply running \u201cvagrant ssh default\u201d, you are now logged into this virtual machine! &nbsp;You also have full sudo to become root and do any sort of damage you may wish to do. &nbsp;If you logout (\u201cexit\u201d or CTRL-D), and type \u201cvagrant destroy\u201d, the VM goes away and you have nothing in Virtualbox.<\/p>\n\n\n\n<p>Were we to just stop here, the power inherent in being able to just have these \u201cVagrantfiles\u201d (sort of like a \u201cMakefile\u201d for boxes) to spin up and down test scenarios at will is incredible. &nbsp;But, let\u2019s look at this in light of the Vagrantfile, what it can do and how you can customize it. &nbsp;There is an entire descriptive language surrounding Vagrant PLUS Vagrant has a plugin infrastructure whereby developers can extend Vagrant\u2019s capabilities. &nbsp;We will capitalize on these later.<\/p>\n\n\n\n<p>So, imagine a scenario where you can create a directory, copy a text file into it, run a single command, and it automatically provisions a 4-node Puppet Enterprise infrastructure, fully installed with a master and three agents, MCollective fully installed, PuppetDB installed and in use\u2026 &nbsp;literally a full installation just like you would use for your infrastructure\u2026 &nbsp;Now we get powerful. &nbsp;NOW we have the ability to do some cool things.<\/p>\n\n\n\n<p>Next time, that\u2019s exactly what we\u2019re going to do.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>So far we\u2019ve gotten our heads around some important things. &nbsp;First and foremost, vim. &nbsp;Our editor and companion for creating great code and ways to see our code in action and be able to determine at a glance whether our syntax is correct. &nbsp;Also, we\u2019ve looked at revision control. &nbsp;The single largest \u201cCYA\u201d ohmygodimgladivegotanoldercopytorestoreto sort [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[4],"tags":[],"class_list":["post-253","post","type-post","status-publish","format-standard","hentry","category-puppet-education"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/questy.org\/index.php\/wp-json\/wp\/v2\/posts\/253","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/questy.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/questy.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/questy.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/questy.org\/index.php\/wp-json\/wp\/v2\/comments?post=253"}],"version-history":[{"count":2,"href":"https:\/\/questy.org\/index.php\/wp-json\/wp\/v2\/posts\/253\/revisions"}],"predecessor-version":[{"id":255,"href":"https:\/\/questy.org\/index.php\/wp-json\/wp\/v2\/posts\/253\/revisions\/255"}],"wp:attachment":[{"href":"https:\/\/questy.org\/index.php\/wp-json\/wp\/v2\/media?parent=253"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/questy.org\/index.php\/wp-json\/wp\/v2\/categories?post=253"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/questy.org\/index.php\/wp-json\/wp\/v2\/tags?post=253"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}