<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>vStone Blog &#187; Puppet</title>
	<atom:link href="http://vstone.eu/category/linux/puppet/feed/" rel="self" type="application/rss+xml" />
	<link>http://vstone.eu</link>
	<description>Random articles about open source and anything else that makes my ticker tick.</description>
	<lastBuildDate>Wed, 18 Apr 2012 05:18:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Vagrant: Using the shell provider for running puppet.</title>
		<link>http://vstone.eu/vagrant-using-the-shell-provider-for-running-puppet/</link>
		<comments>http://vstone.eu/vagrant-using-the-shell-provider-for-running-puppet/#comments</comments>
		<pubDate>Wed, 18 Apr 2012 05:14:05 +0000</pubDate>
		<dc:creator>vStone</dc:creator>
				<category><![CDATA[Puppet]]></category>
		<category><![CDATA[Vagrant]]></category>

		<guid isPermaLink="false">http://vstone.eu/?p=195</guid>
		<description><![CDATA[The case for&#8230; Why would you use the shell provider instead of the native puppet support? Sometimes you want to tweak your base-box before running puppet, in that case, using a shell script might be a good idea. I started &#8230; <a href="http://vstone.eu/vagrant-using-the-shell-provider-for-running-puppet/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<h2>The case for&#8230;</h2>
<p>Why would you use the shell provider instead of the native puppet support?</p>
<p>Sometimes you want to tweak your base-box before running puppet, in that case, using a shell script might be a good idea. I started using the shell provider for deploying a puppetmaster. This way, I can initially bootstrap the puppetmaster using puppet apply and then have further configuration done by letting further configuration be done by just running puppet agent like I would in an actual environment.</p>
<p>The second advantage is that I sync my complete puppet tree to /etc/puppet vagrant box, making the differences with an actual deploy even smaller. If you need custom configuration files, you can use the proper file paths while developing and/or put them in your puppet folder.<br />
<span id="more-195"></span></p>
<h2>The setup</h2>
<p>This is how my folder structure looks:</p>
<pre> .
 ├── <strong style="color:blue;">graphs</strong>
 ├── <strong style="color:blue;">puppet</strong>
 │&nbsp;&nbsp; ├── <strong style="color:blue;">hieradata</strong>
 │&nbsp;&nbsp; ├── <strong style="color:blue;">manifests</strong>
 │&nbsp;&nbsp; ├── <strong style="color:blue;">modules</strong>
 │&nbsp;&nbsp; └── hiera.yaml
 ├── <strong style="color:blue;">scripts</strong>
 │&nbsp;&nbsp; ├── <strong style="color:green;">deploy_puppetmaster.sh</strong>
 │&nbsp;&nbsp; └── <strong style="color:green;">run_puppet.sh</strong>
 ├── README
 └── Vagrantfile
</pre>
<p>As you can see, stuff is nicely separated. Note that this also allows me to put a <em>hiera.yaml</em> file in place for use with hiera. When using the vagrant puppet provisioning, the hiera.yaml file must be present in the base-box. It also allows me to use git submodules for each part (e.g. the puppet directory which is a collection of more submodules).</p>
<h3>Vagrantfile</h3>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#6666ff; font-weight:bold;">Vagrant::Config</span>.<span style="color:#9900CC;">run</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>config<span style="color:#006600; font-weight:bold;">|</span>
  config.<span style="color:#9900CC;">vm</span>.<span style="color:#9900CC;">define</span> <span style="color:#ff3333; font-weight:bold;">:client</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>client_config<span style="color:#006600; font-weight:bold;">|</span>
    client_config.<span style="color:#9900CC;">vm</span>.<span style="color:#9900CC;">box</span> = <span style="color:#996600;">&quot;base&quot;</span>
    client_config.<span style="color:#9900CC;">vm</span>.<span style="color:#9900CC;">host_name</span> = <span style="color:#996600;">&quot;client&quot;</span>
    client_config.<span style="color:#9900CC;">vm</span>.<span style="color:#9900CC;">provision</span> <span style="color:#ff3333; font-weight:bold;">:shell</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>shell<span style="color:#006600; font-weight:bold;">|</span>
      shell.<span style="color:#9900CC;">path</span> = <span style="color:#996600;">&quot;scripts/run_puppet.sh&quot;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<h3>Run Puppet</h3>
<p>For running a puppet agent, I use the following script:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #000000; font-weight: bold;">set</span> <span style="color: #660033;">-x</span>
&nbsp;
<span style="color: #666666; font-style: italic;">## We need rsync on the machine</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>rsync <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">||</span> yum <span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #660033;">-y</span> rsync
<span style="color: #666666; font-style: italic;"># As a (faster) alternative, download the rpm locally and use:</span>
<span style="color: #666666; font-style: italic;"># rpm -i /vagrant/rsync-3.0.6-5.el6_0.1.x86_64.rpm</span>
&nbsp;
<span style="color: #666666; font-style: italic;">## We need hiera - should be replaced by a rpm someday.</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>hiera <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">||</span> gem <span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #660033;">-r</span> <span style="color: #660033;">--no-rdoc</span> <span style="color: #660033;">--no-ri</span> hiera hiera-puppet
&nbsp;
<span style="color: #666666; font-style: italic;">## We also need the puppet folder</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-d</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>puppet <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>puppet
&nbsp;
<span style="color: #666666; font-style: italic;">## Sync the puppet tree from the vagrant folder to the machine.</span>
rsync <span style="color: #660033;">-alrcWt</span> <span style="color: #660033;">--del</span> <span style="color: #660033;">--progress</span> \
  <span style="color: #660033;">--exclude</span>=.git <span style="color: #660033;">--exclude</span>=.svn \
  <span style="color: #000000; font-weight: bold;">/</span>vagrant<span style="color: #000000; font-weight: bold;">/</span>puppet<span style="color: #000000; font-weight: bold;">/*</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>puppet<span style="color: #000000; font-weight: bold;">/</span>
&nbsp;
puppet apply <span style="color: #660033;">--debug</span> <span style="color: #660033;">--verbose</span> \
  <span style="color: #660033;">--graph</span> <span style="color: #660033;">--graphdir</span> <span style="color: #000000; font-weight: bold;">/</span>vagrant<span style="color: #000000; font-weight: bold;">/</span>graphs \
  <span style="color: #660033;">--modulepath</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>puppet<span style="color: #000000; font-weight: bold;">/</span>modules<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>puppet<span style="color: #000000; font-weight: bold;">/</span>manifests<span style="color: #000000; font-weight: bold;">/</span>site.pp</pre></div></div>

<h3>Deploy a Puppetmaster</h3>
<p>For deploying / testing a puppet server, I use a slightly different script.</p>
<p>This will first bootstrap the puppet master using the same puppet apply method we use for testing a &#8216;client&#8217; &#8211; but this will only perform minimal configuration. Once we have a puppetmaster running, we run a puppet agent on the machine that will configure the server against itself.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #000000; font-weight: bold;">set</span> <span style="color: #660033;">-x</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>rsync <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">||</span> yum <span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #660033;">-y</span> rsync
<span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>hiera <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">||</span> gem <span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #660033;">-r</span> <span style="color: #660033;">--no-rdoc</span> <span style="color: #660033;">--no-ri</span> hiera hiera-puppet
<span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-d</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>puppet <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>puppet
&nbsp;
<span style="color: #666666; font-style: italic;">## Sync the puppet tree from the vagrant folder to the puppet folder on the machine.</span>
rsync <span style="color: #660033;">-alrcWt</span> <span style="color: #660033;">--del</span> <span style="color: #660033;">--progress</span> \
  <span style="color: #660033;">--exclude</span>=.git <span style="color: #660033;">--exclude</span>=.svn \
  <span style="color: #000000; font-weight: bold;">/</span>vagrant<span style="color: #000000; font-weight: bold;">/</span>puppet<span style="color: #000000; font-weight: bold;">/*</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>puppet<span style="color: #000000; font-weight: bold;">/</span>
&nbsp;
<span style="color: #666666; font-style: italic;">## Execute the bootstrap</span>
puppet apply <span style="color: #660033;">--debug</span> <span style="color: #660033;">--verbose</span> <span style="color: #660033;">--trace</span> \
  <span style="color: #660033;">--graph</span> <span style="color: #660033;">--graphdir</span> <span style="color: #000000; font-weight: bold;">/</span>vagrant<span style="color: #000000; font-weight: bold;">/</span>graphs \
  <span style="color: #660033;">--modulepath</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>puppet<span style="color: #000000; font-weight: bold;">/</span>modules \
  <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;import '/etc/puppet/manifests/classes/required-repos.pp' <span style="color: #000099; font-weight: bold;">\
</span>      import '/etc/puppet/manifests/classes/puppetmaster.pp' <span style="color: #000099; font-weight: bold;">\
</span>      include puppetmaster::bootstrap&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">## Continue configuration using the set up puppetmaster</span>
puppet agent <span style="color: #660033;">--test</span> <span style="color: #660033;">--debug</span> <span style="color: #660033;">--verbose</span></pre></div></div>

<p>I will not go into detail on what the puppetmaster manifest contain (for now) since I am still working on a demo setup. You can take a quick peek to the work that is done on this subject here: <a href="https://projects.vstone.eu/projects/puppet-showcase-puppetmaster" title="Bootstrapped Puppetmaster Demo" target="_blank">https://projects.vstone.eu/projects/puppet-showcase-puppetmaster</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://vstone.eu/vagrant-using-the-shell-provider-for-running-puppet/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Why not to use Puppet::Parser::Functions.autoloader.loadall</title>
		<link>http://vstone.eu/why-not-to-use-puppetparserfunctions-autoloader-loadall/</link>
		<comments>http://vstone.eu/why-not-to-use-puppetparserfunctions-autoloader-loadall/#comments</comments>
		<pubDate>Tue, 31 Jan 2012 10:43:39 +0000</pubDate>
		<dc:creator>vStone</dc:creator>
				<category><![CDATA[Puppet]]></category>
		<category><![CDATA[puppet]]></category>
		<category><![CDATA[tips-n-tricks]]></category>

		<guid isPermaLink="false">http://vstone.eu/?p=187</guid>
		<description><![CDATA[Recently (about 5 minutes ago), I was writing a custom puppet-function to offload some puppet magic. In short: I&#8217;m writing a wrapper around create_resources so I can keep syntax for the end-users of my module crispy clean. This means I &#8230; <a href="http://vstone.eu/why-not-to-use-puppetparserfunctions-autoloader-loadall/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Recently (about 5 minutes ago), I was writing a custom puppet-function to offload some puppet magic. In short: I&#8217;m writing a wrapper around <a title="Puppetlabs Function Guide: create_resources" href="http://docs.puppetlabs.com/references/stable/type.html#create_resources" target="_blank"><em>create_resources</em></a> so I can keep syntax for the end-users of my module crispy clean. This means I need the <em>create_resources</em> function to be available in my custom function. This can be done by using <em>Puppet::Parser::Functions.autoloader.loadall</em> as suggested on the <a title="Puppetlabs Guide: Custom Functions" href="http://docs.puppetlabs.com/guides/custom_functions.html" target="_blank">puppetlabs custom modules guide</a>. Unfortunately, when using <em>#loadall</em>, all functions will be loaded.</p>
<p><em>Why unfortunately</em>? In my case: A function defined in puppet-foreman depends on the rest-client gem and I do not have this installed. Some people might say: Just install the gem and be done with it! This is hardly a proper solution. The way to go would to be only include the function I really  need, being <em>create_resources</em>.</p>
<p>And here is how:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#6666ff; font-weight:bold;">Puppet::Parser::Functions</span>.<span style="color:#9900CC;">autoloader</span>.<span style="color:#CC0066; font-weight:bold;">load</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:create_resources</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">unless</span> <span style="color:#6666ff; font-weight:bold;">Puppet::Parser::Functions</span>.<span style="color:#9900CC;">autoloader</span>.<span style="color:#9900CC;">loaded</span>?<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:create_resources</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>This will basically load the <em>create_resources</em> function after checking that it has not been loaded before. This (the function already being loaded) could be the case if you properly depend on puppetlabs-create_resources in your manifests. Side note: I <a title="Added a dummy class for inclusion." href="https://github.com/puppetlabs/puppetlabs-create_resources/pull/4" target="_blank">added a small dummy class</a> so my modules can depend on this function being available.</p>
<p>This has resolved my issues with <em>#loadall</em>, but if I ever needed to include another function that DOES use <em>#loadall</em>, I&#8217;ll be screwed all over again. So (pretty) pls, don&#8217;t use <em>#loadall</em>.</p>
]]></content:encoded>
			<wfw:commentRss>http://vstone.eu/why-not-to-use-puppetparserfunctions-autoloader-loadall/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Puppet Module Patterns</title>
		<link>http://vstone.eu/puppet-module-patterns/</link>
		<comments>http://vstone.eu/puppet-module-patterns/#comments</comments>
		<pubDate>Mon, 30 Jan 2012 17:30:58 +0000</pubDate>
		<dc:creator>vStone</dc:creator>
				<category><![CDATA[Puppet]]></category>
		<category><![CDATA[puppet]]></category>

		<guid isPermaLink="false">http://vstone.eu/?p=74</guid>
		<description><![CDATA[INTRODUCTION I&#8217;ve used puppet quite intensively since a couple of months (about 4 I would guess). Before that, I&#8217;ve played with it, change something here and there. But quite not as much as now. I&#8217;ve used several puppet modules from &#8230; <a href="http://vstone.eu/puppet-module-patterns/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<h3 id="introduction">INTRODUCTION</h3>
<p>I&#8217;ve used puppet quite intensively since a couple of months (about 4 I would guess). Before that, I&#8217;ve played with it, change something here and there. But quite not as much as now. I&#8217;ve used several puppet modules from wherever google leads me, roamed github, inherited a few from colleagues and created several from scratch. While doing so, I saw a lot of stuff I disliked and learned a lot on how we I can (ab)use puppet to do what I want it to do. Over those last months, I have grown my set of ideas on how a puppet module should look. So, before every statement I make, you should probably add &#8216;IMHO&#8217;.</p>
<p><span id="more-74"></span></p>
<h3 id="who">WHO THE F.</h3>
<p><em>Why the hell would this guy (me) have anything to say about puppet modules</em>. Let&#8217;s situate first.</p>
<p>I&#8217;m now an Open Source Consultant. I&#8217;ve been (in order) a Java programmer, sysadmin, Drupal developer and now back sysadmin (doing devopsy things). Last 3 positions I worked for (and still work for): <a title="Inuits" href="http://inuits.eu" target="_blank">Inuits</a> &#8211; Open Source company in Belgium. Currently, I&#8217;m positioned at <a title="UnifiedPost" href="http://unifiedpost.com" target="_blank">UnifiedPost</a> (About 100 people but thinking big!). I help out with daily maintenance (and there is plenty) and starting to adopt puppet as much as possible. Puppet was already in use at UP (UnifiedPost), but knowledge was rather thin as I came in. They did however manage some hosts with it (about 300-400). I dove in the puppet code rather fast and stumbled upon several patterns that increased pressure on my mouse heavily. Even modules I grabbed from the net (whatever the source is) made my grip firmer.</p>
<h3 id="problems">PROBLEMS</h3>
<p>Before trying to fix the problem, we should find exactly what bothers me with all these modules I lay my eyes on. I&#8217;ll try to keep it organized.</p>
<ol>
<li>Modules are not classes!</li>
<li>Too hard to use by non-developers</li>
<li>Poor interaction with third-party modules</li>
<li>Not versioned</li>
<li>Not pretty at all do down right f_ugly</li>
</ol>
<h4 id="modules-are-not-classes">1. Modules are not classes!</h4>
<p>Although a module exists out of several classes, it should not behave like one.</p>
<p>An example to clarify what I mean: The accounts <em>module</em>. (I&#8217;m sure this is the case for may organizations that have an accounts module).</p>
<p>I can think of a several valid reasons why you would have one. (Keep reading nevertheless!). What does our accounts module contain: A definition to ease the use and do some customization (set defaults, create some files, &#8230;). We also find a list of users, passwords and authorized_ssh keys. This (specific) user information does not belong in a module. It should either be in a class (below the manifests folder) or stored externally. In my point of view: Nodes use classes. They register the kind of machine and define what should be installed. Classes include modules and change settings. Possibly parameterized so we can keep it node specific. All module parameters values reside in the node or the class(es) it includes.</p>
<h4 id="too-hard-to-use">2. Too hard to use by non-developers</h4>
<p>This brings us to our next point. Can I just grab your module and start using it? Or do I need to weed out hardcoded strings, change host names or edit templates. Do I need to understand the complete way it works &#8216;under the hood&#8217;. I have written a short <a title="Puppet modules and using dot graphs (both are unrelated but related to each other)" href="http://vstone.eu/puppet-modules-and-using-dot-graphs-both-are-unrelated-but-related-to-each-other/" target="_blank">post</a> recently, expressing my feelings about this. Bottom line: If I need to edit any file within your module to get it working the way I want it to, there is something wrong with it. Sure, features and/or support might be missing. but if my $::operatingsystem is supported, I should get it working without touching anything of the module code.</p>
<h4 id="poor-interaction">3. Poor interaction with third-party modules</h4>
<p>I have reused (or attempted to) several modules found on github and always had the same problem, it does not play well with our current puppet-tree. The best example for this is probably the apache (or httpd) module. Almost any puppet modules that has a dependency on apache being installed, comes with its own implementation and/or dependency. Most companies already have a apache module and change the new module to work properly together with theirs. <em>There goes upstream support</em>. I have run into this issue with puppet-foreman recently and this will probably be my first big test case for my coding pattern.</p>
<h4 id="not-versioned">4. Not versioned</h4>
<p>Most modules you will find only live on one branch, master. Some may have a develop branch, but most of the time, there is no saying in what version you are using. Unless you elevate hash-tags to version numbers. (Using git submodules does this at some extend). But updating a submodule is always a dangerous thing to do, there is no way to tell what will break.</p>
<p>Besides the &#8216;version&#8217; of a module, we also have to take the puppet version into account. I tend to be a cutting-edge user for all my software, but I can easily understand if you don&#8217;t for whatever reason. So keeping puppet-modules backwards compatible is a must (is it?).</p>
<h4 id="not-pretty-formatted">5. Not <span style="color: #ffcc00;">p<span style="color: #ff00ff;">r</span><span style="color: #ff0000;">e</span><span style="color: #33cccc;">t</span><span style="color: #339966;">t</span><span style="color: #0000ff;">y</span></span> at all do down right f_ugly</h4>
<p>Why is properly formatted code important: for anybody else that ever has to ever change or even use it. This could be a colleague or someone (anyone) else that found your module and wants to improve (here is when YOU win time, if somebody else does the job for you) or change it. Even if you did not have time for writing up documentation, most people will have to stroll through your code. Having properly formatted code is always a nice-to-have feature then.</p>
<h3 id="requirements">REQUIREMENTS</h3>
<p>So now that we know what I dislike about puppet modules, let&#8217;s try to define something more positive. What is a good baseline for a puppet-module.</p>
<ol start="0">
<li>VCS (This one is pretty obvious, I will not elaborate on this any further.)</li>
<li>Follows <a title="Puppet Style Guide" href="http://docs.puppetlabs.com/guides/style_guide.html">style guidelines</a></li>
<li>Use of centralized parameters / settings</li>
<li>Fully(!) parameterized</li>
<li>Easy and centralized handling of compatibility (<em>$::operatingsystem</em>-ish stuff)</li>
<li>Documented</li>
<li>Releases</li>
<li>Puppet compatibility</li>
<li>Integration: is uniquely identifiable</li>
<li>Easy to extend</li>
</ol>
<h4 id="style-guidelines">1. Style Guidelines</h4>
<p>Why? Some valid reasons are so you make fewer mistakes and are more aware of what you are doing Do you really need double quotes? Using single quotes for static string values will prevent you from forgetting to quote &#8216;$&#8217; (commands anyone?). Always using a default case will make you more aware that more than one distro exists in the world. At least fail when your module is not fit for a certain operating system to prevent unexpected behavior. If you read through the style guideline, you will see that many of these items are easily to do if you just remember to do so when you are writing the actual code.</p>
<h4 id="centralized-parameters-settings">2. Centralized parameters / settings</h4>
<p>Does your module support <em>distro</em>? Just check the params.pp file. Everything is there. It does not get much easier than this to add support for a new distro.</p>
<h4 id="fully-parameterized">3. Fully Parameterized</h4>
<p>This might seem like I&#8217;m making the same point twice, but we should differentiate between our general &#8216;settings&#8217; that configure the working of our module, and specific definitions that have parameters. You define where all your vhosts are but each vhosts definition you create also takes parameters. Same rule applies for a definition as for a module, we should be able to use it without having to change anything in the code. Often, this means making more stuff than you need &#8211; at time of writing your module &#8211; dynamical (parameterized). You can hard-code a &#8216;Listen 80&#8242; or template it using a $ports parameter.</p>
<h4 id="compatibility handling">4. Compatibility handling</h4>
<p>As an exampe: my colleague asked me: <em>Does your module work for Debian</em>? I was happy to answer: You just need to add support to the params.pp file. That&#8217;s all whats needed (and maybe add some templates).</p>
<h4 id="documentation">5. Documentation</h4>
<p>When thinking as a developer when writing a module, we know we need to offer easy documentation for the end-user. This is no different when writing a puppet module. It&#8217;s always a good thing to keep people out of your code as much as possible. Proper documentation is the first step. I try to write as much as possible, main reason being when a colleague asks how to use it, I can point him to the documentation instead of going over the code myself to remember what exactly is going on. On a side note: ATM, I&#8217;m having some troubles with <a title="Hash in class parameter breaks doc generation" href="http://projects.puppetlabs.com/issues/11384">bug #11384</a>. Votes &#8211; and a patch even more &#8211; welcome ;)</p>
<p>Beside top-level documentation, inline (code) documentation should also be written. Not for the obvious stuff, but when you do something more advanced, explain to a fellow coder (or yourself some weeks later) why and what you are doing.</p>
<h4 id="releases">6. Releases</h4>
<p>Puppet modules should also have releases. This would an easier way of drawing attention when we change the API (or definition parameters) or when we fix a bug. This is also a great sign when our module is no longer backward compatible with old code (breaking API). I try to support old code as much as possible. But at some point, we will have to weed the old so it does not clutter the new. Keeping stuff simple/stupid (although I have passed that bridge a looooong time) is still a good principle.</p>
<h4>7. Puppet Compatibility</h4>
<p>We need to know with what version of puppet your module is compatible. Some features of the puppet language you use might or might not be available in older releases. You can check the <a title="Puppet Language Guide" href="http://docs.puppetlabs.com/guides/language_guide.html" target="_blank">Puppet Language Guide</a> for what is introduced in what version, but there are a lot of other differences that are not so much documented. I&#8217;ve been using the create_resources function quite a lot but it&#8217;s only in core puppet for versions 2.7 and up. Luckily, there is <a title="Function to dynamically create resources from hashes" href="https://github.com/puppetlabs/puppetlabs-create_resources" target="_blank">a backport for 2.6 on the puppetlabs&#8217; github</a>.</p>
<h4 id="integration-is-uniquely-identifiable">8. Integration:  is uniquely identifiable</h4>
<p>To improve compatibility, we first need must be able to tell what module we are integrating with. I personally started to use a $modulename and $moduleversion param in the main class of my module. Modulefiles like puppetlabs requires them for the puppet forge are cool, but we can not use them in our code.  We could write a fact for this so we don&#8217;t need to duplicate code. I won&#8217;t add this to my to-do list as I already have a way-to-long backlog, but feel free to add it to yours.</p>
<p>With this information, we could do different things based on the module and version we are working with.</p>
<h4 id="easy-to-extend">9. Easy to extend</h4>
<p>In this part, the developer in me is taking the overhand and it will depend on personal preference a lot more than any of the previous points. A quick example: I wanted to use a conf.d/* configuration style. Even more, for certain configuration files, order is important so we need to prefix files with 00_, 01_, &#8230; I could have easily done this for each type of configuration file I want to store here. In stead, I wrote a confd wrapper definition/class that does this for me. It&#8217;s a 2 step process: You <a title="Conf.d style folder example (a listen.d folder)" href="https://github.com/Inuits/puppet-apache/blob/feature/confd_style/manifests/setup/listen.pp" target="_blank">initialize/setup</a> a<a title="Conf.d base helper" href="http://vstone.eu/puppet-modules-and-using-dot-graphs-both-are-unrelated-but-related-to-each-other/" target="_blank"> conf.d folder</a> and then <a title="Example usage of a conf.d folder" href="https://github.com/Inuits/puppet-apache/blob/feature/confd_style/manifests/listen.pp" target="_blank">define</a> your<a title="conf.d different file types." href="https://github.com/Inuits/puppet-apache/blob/feature/confd_style/manifests/confd" target="_blank">resources</a> within them. I&#8217;m realizing now that this should have been a separate module. I have added it to my <a title="Split off conf.d logic Issue" href="https://github.com/Inuits/puppet-apache/issues/2" target="_blank">to-do</a> list.The main advantage is I can easily re-implement conf.d style folders now without worrying about the logic behind it.</p>
<h3 id="solutions">SOLUTIONS</h3>
<p>Quick wins! These go without saying, start using them now.</p>
<h4 id="check-style-formatting">Check your code for formatting and style.</h4>
<p>For this, we have<a title="Puppet-lint project on github." href="http://github.com/rodjek/puppet-lint"> puppet-lint</a>. This tool will deal with most common problems and errors/warnings against the style guide. This tool takes one puppet manifest as argument and displays the errors/warnings it finds. You can easily<a title="Puppet modules in Jenkins." href="http://vstone.eu/puppet-modules-in-jenkins/"> integrate it with jenkins</a> since the log-format argument has been added.</p>
<h4>Documentation.</h4>
<p>I suppose most people will have issues with this. Good documentation is essential and not much hard work if you do it right. I prefer to START with documenting what a class will do and implement afterwards. This is a lot like writing tests first and then use them to see if you are writing proper / working code. The danger is of course that you change the internal working but forget to update your documentation. After each feature I add, I tend to go over the documentation and see that everything is still up to date. Once documentation has been written, you can generate it using<em> puppet doc</em>. To work around certain puppet doc&#8217;s ugliness, I wrote a small wrapper script for my Jenkins jobs that does some post processing on them. See <a title="Puppet modules in Jenkins." href="http://vstone.eu/puppet-modules-in-jenkins/">previous post</a> for that.</p>
<h4>Releases</h4>
<p>I&#8217;ll be quick about this one: Use <a title="A successful Git branching model: git-flow" href="http://nvie.com/posts/a-successful-git-branching-model/" target="_blank">git-flow</a>.</p>
<h4>General / Initial module structure.</h4>
<p>For creating your initial puppet module structure, there is always the puppet-module tool. Install it by installing the gem. I have tried using it, but I&#8217;m relying on my <a title="My additions to my bashrc for doing puppet." href="https://github.com/vStone/vStone-various/blob/master/bash-scripts/bashrc_puppet" target="_blank">own bash magic</a> for creating classes.</p>
<p>This is my basic structure I re-use over and over.</p>
<ul>
<li>./manifests/init.pp</li>
<li>./manifests/params.pp</li>
<li>./manifests/packages.pp</li>
<li>./manifests/setup.pp</li>
</ul>
<p>One note on these filenames: always try to avoid confusion! I have seen a lot of config.pp classes and params.pp classes where the config.pp actually does configuration of the package on the system while params.pp is for configuring the behavior of the puppet-module. I like setup.pp better than config.pp, since it&#8217;s easier to figure out what the class does: It sets up the system! Another good option would be install.pp.</p>
<h3>OUTRO</h3>
<p>I realize these solutions are no where near finished but since FOSDEM 2012 is coming up and I&#8217;m running low on time, I wanted to publish this post so anybody can starting giving their opinion on the matter before coming to a final out-of-the-box solution most people can relate to. So, actually, this is a big fat <strong>TO BE CONTINUED</strong>.</p>
<p>Matters we need to discuss:</p>
<ul>
<li>Compatibility handling (both to other modules and puppet)</li>
<li>Making modules easy to integrate and/or extend.</li>
</ul>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://vstone.eu/puppet-module-patterns/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Puppet modules in Jenkins.</title>
		<link>http://vstone.eu/puppet-modules-in-jenkins/</link>
		<comments>http://vstone.eu/puppet-modules-in-jenkins/#comments</comments>
		<pubDate>Sat, 21 Jan 2012 18:39:35 +0000</pubDate>
		<dc:creator>vStone</dc:creator>
				<category><![CDATA[Puppet]]></category>
		<category><![CDATA[jenkins]]></category>
		<category><![CDATA[puppet]]></category>

		<guid isPermaLink="false">http://vstone.eu/?p=106</guid>
		<description><![CDATA[Code style checking Prerequisites: You will need a recent enough version of puppet-lint that supports the --log-format flag. Install the gem so that the Jenkins can use it. On Jenkins, you will need the Warnings Plugin and the HTML Publisher &#8230; <a href="http://vstone.eu/puppet-modules-in-jenkins/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<h2>Code style checking</h2>
<h3>Prerequisites:</h3>
<ul>
<li>You will need a recent enough version of <a title="Puppet-lint project on github." href="http://github.com/rodjek/puppet-lint" target="_blank">puppet-lint</a> that supports the <code>--log-format</code> flag. Install the gem so that the Jenkins can use it.</li>
<li>On Jenkins, you will need the <a title="Jenkins: Warnings Plugin" href="https://wiki.jenkins-ci.org/display/JENKINS/Warnings+Plugin" target="_blank">Warnings Plugin</a> and the<a title="Jenkins: HTML Publisher Plugin" href="https://wiki.jenkins-ci.org/display/JENKINS/HTML+Publisher+Plugin" target="_blank"> HTML Publisher Plugin</a>.</li>
<li>Make sure that when checking the module from your VCS, it ends up in WORKSPACE/modules/module_name.</li>
</ul>
<h3>Configuration:</h3>
<h4>Jenkins</h4>
<p><del>Go to the <em>Configure System</em> page and find the <em>Compiler Warnings</em> settings. Add a new console log parser and call it puppet-lint. I use following configuration for parsing puppet-lint warnings and errors.</del></p>
<p>The warnings plugin has been updated and now has puppet-lint support out of the box! So configuring puppet-lint manually is kind of useless now.</p>
<p><strong>Name:</strong></p>
<pre>puppet-lint</pre>
<p><strong>Regular Expression:</strong></p>
<pre>^\s*([^:]+):([0-9]+):([^:]+):([^:]+):\s*(.*)$</pre>
<p><strong>Mapping Script:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="groovy" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #a1a100;">hudson.plugins.warnings.parser.Warning</span>
<span style="color: #808080; font-style: italic;">// map regular expression to strings</span>
<span style="color: #aaaadd; font-weight: bold;">String</span> fileName <span style="color: #66cc66;">=</span> matcher.<span style="color: #006600;">group</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
<span style="color: #aaaadd; font-weight: bold;">String</span> lineNumber <span style="color: #66cc66;">=</span> matcher.<span style="color: #006600;">group</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
<span style="color: #aaaadd; font-weight: bold;">String</span> kind <span style="color: #66cc66;">=</span> matcher.<span style="color: #006600;">group</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
<span style="color: #aaaadd; font-weight: bold;">String</span> check <span style="color: #66cc66;">=</span> matcher.<span style="color: #006600;">group</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">4</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
<span style="color: #aaaadd; font-weight: bold;">String</span> message <span style="color: #66cc66;">=</span> matcher.<span style="color: #006600;">group</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">5</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
<span style="color: #808080; font-style: italic;">// return a Warning.</span>
<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">new</span> Warning<span style="color: #66cc66;">&#40;</span>fileName, <span style="color: #aaaadd; font-weight: bold;">Integer</span>.<span style="color: #006600;">parseInt</span><span style="color: #66cc66;">&#40;</span>lineNumber<span style="color: #66cc66;">&#41;</span>, check, kind, message<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span></pre></div></div>

<p><strong>Example Log Message:</strong><code></code></p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">./manifests/params.pp:25:autoloader_layout:error:apache::params not in autoload module layout</pre></div></div>

<h4>Jenkins job configuration</h4>
<p>We will add several <strong>build steps</strong> that will run certain actions on our puppet modules.</p>
<ol>
<li>Check syntax</li>
<li>Check style</li>
<li>Generate documentation</li>
</ol>
<p>1. For the <strong>syntax check</strong>, I use following shell script (add a build step):</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">for</span> <span style="color: #c20cb9; font-weight: bold;">file</span> <span style="color: #000000; font-weight: bold;">in</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">find</span> . <span style="color: #660033;">-iname</span> <span style="color: #ff0000;">'*.pp'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>; <span style="color: #000000; font-weight: bold;">do</span>
  puppet parser validate <span style="color: #660033;">--color</span> <span style="color: #c20cb9; font-weight: bold;">false</span> <span style="color: #660033;">--render-as</span> s <span style="color: #660033;">--modulepath</span>=modules <span style="color: #007800;">$file</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>;
<span style="color: #000000; font-weight: bold;">done</span>;</pre></div></div>

<p>2. For the <strong>style check</strong>, we use puppet-lint (add another build step):</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">find</span> . <span style="color: #660033;">-iname</span> <span style="color: #000000; font-weight: bold;">*</span>.pp <span style="color: #660033;">-exec</span> puppet-lint <span style="color: #660033;">--log-format</span> <span style="color: #ff0000;">&quot;%{path}:%{linenumber}:%{check}:%{KIND}:%{message}&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span> \;</pre></div></div>

<p>3. And for generating <strong>documentation</strong>:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">## Cleanup old docs.</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-d</span> doc<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;</span>amp;<span style="color: #000000; font-weight: bold;">&amp;</span>amp; <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-rf</span> doc<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #666666; font-style: italic;">## Dummy manifests folder.</span>
<span style="color: #000000; font-weight: bold;">!</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-d</span> manifests<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;</span>amp;<span style="color: #000000; font-weight: bold;">&amp;</span>amp; <span style="color: #c20cb9; font-weight: bold;">mkdir</span> manifests<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #666666; font-style: italic;">## Generate docs</span>
puppet doc <span style="color: #660033;">--mode</span> rdoc <span style="color: #660033;">--manifestdir</span> manifests<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #660033;">--modulepath</span> .<span style="color: #000000; font-weight: bold;">/</span>modules<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #660033;">--outputdir</span> doc
&nbsp;
<span style="color: #666666; font-style: italic;">## Fix docs to how I want them, I don't like that the complete workspace is included in all file paths.</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-d</span> <span style="color: #800000;">${WORKSPACE}</span><span style="color: #000000; font-weight: bold;">/</span>doc<span style="color: #000000; font-weight: bold;">/</span>files<span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${WORKSPACE}</span><span style="color: #000000; font-weight: bold;">/</span>modules <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
  <span style="color: #c20cb9; font-weight: bold;">mv</span> <span style="color: #660033;">-v</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${WORKSPACE}</span>/doc/files/<span style="color: #007800;">${WORKSPACE}</span>/modules&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${WORKSPACE}</span>/doc/files/modules&quot;</span>
<span style="color: #000000; font-weight: bold;">fi</span>;
<span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-l</span> <span style="color: #660033;">-R</span> <span style="color: #800000;">${WORKSPACE}</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #c20cb9; font-weight: bold;">read</span> fname; <span style="color: #000000; font-weight: bold;">do</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-i</span> <span style="color: #ff0000;">&quot;s@<span style="color: #007800;">${WORKSPACE}</span>/@/@g&quot;</span> <span style="color: #007800;">$fname</span>; <span style="color: #000000; font-weight: bold;">done</span>;</pre></div></div>

<p>In your <strong>post build</strong> section:</p>
<ul>
<li>Enable <em>Scan for compiler warnings</em> and select <em>puppet-lint</em>.</li>
<li>Enable publish HTML reports (use &#8216;<em>doc</em>&#8216;, &#8216;<em>index.html</em>&#8216; and &#8216;<em>Puppet Docs</em>&#8216; as values). This will add a link to the Job page linking your generated puppet docs.</li>
</ul>
<p>That&#8217;s about it! Any suggestions / improvements on this are always welcome!</p>
<h3>Notes:</h3>
<ul>
<li>I have some examples/tests setup on my Jenkins instance for testing at <a href="http://jenkins.vstone.eu">http://jenkins.vstone.eu</a>. Since I use this for testing, it might be offline / broken / buggy at times.</li>
<li>The scripts I use may also require some changes if you are using an older version of puppet. I&#8217;m currently using 2.7.x for testing my modules.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://vstone.eu/puppet-modules-in-jenkins/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Vagrant quickstart for Puppet dev(op)s</title>
		<link>http://vstone.eu/vagrant-quickstart-for-puppet-devops/</link>
		<comments>http://vstone.eu/vagrant-quickstart-for-puppet-devops/#comments</comments>
		<pubDate>Fri, 07 Oct 2011 16:50:13 +0000</pubDate>
		<dc:creator>vStone</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Puppet]]></category>
		<category><![CDATA[Vagrant]]></category>

		<guid isPermaLink="false">http://vstone.eu/?p=18</guid>
		<description><![CDATA[A quick introduction on how I use vagrant for developing my puppet manifests/modules/. You can almost certain also use this for other purposes. In general, this will get you up to speed fast! We will quickly go over installation and/or &#8230; <a href="http://vstone.eu/vagrant-quickstart-for-puppet-devops/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>A quick introduction on how I use vagrant for developing my puppet manifests/modules/. You can almost certain also use this for other purposes. In general, this will get you up to speed fast!<br />
We will quickly go over <a href="#installation">installation</a> and/or <a href="#updating">updating</a> and maybe even <a href="#removing">removing</a> an old version using ruby gems.<br />
Furthermore: <a href="#add_box">adding</a> a vagrant box and <a href="#setup_project">preparing</a> a project to <a href="#starting_up">develop</a> a puppet module (or something of the likes).<br />
<span id="more-18"></span></p>
<h2>Installation</h2>
<p>Installation is pretty simple. Make sure you have <em>ruby</em> (and <em>ruby gems</em>) installed and run</p>
<pre><strong>[user@hostname ~]$</strong> gem install vagrant</pre>
<p>Also make sure you have the proper virtualbox version installed. Check the website (<a href="http://vagrantup.com/docs/getting-started/index.html">http://vagrantup.com/docs/getting-started/index.html</a>) on what version is required.</p>
<h3>Updating</h3>
<p>These commands should be performed as root or add sudo if you want the gems to be installed for all users.</p>
<p>If you want to install a gem as a user, make sure you add the <code>-n &lt;folder&gt;</code> switch. This allows you to specify where a gem should install its executables. I use <code>-n ~/.local/bin</code> whenever I install something as a user (development versions for example). Make sure to add the folder to your PATH for comfort.</p>
<h4>Checking locally installed versions (optional but as a bonus!)</h4>
<p>Local version:</p>
<pre><strong>[user@hostname ~]$ </strong>gem list vagrant</pre>
<p>Remote versions available:</p>
<pre><strong>[user@hostname ~]$</strong> gem list -r vagrant</pre>
<h4>Update the gem</h4>
<pre><strong>[user@hostname ~]$</strong> gem update vagrant</pre>
<p>&nbsp;</p>
<h4>Removing old versions</h4>
<p>Before removing a gem (any gem), always check if it was not installed by a package.</p>
<pre><strong>[user@hostname ~]$</strong> gem list -d vagrant</pre>
<p>Gems that are installed using <em>gem</em> will be in a <code>/usr/local/lib*</code> dir structure. Gems installed by a package are in <code>/usr/lib*</code>.</p>
<p>To remove a specific version:</p>
<pre><strong>[user@hostname ~]$</strong> gem uninstall -v 0.7.5 vagrant</pre>
<h2>Getting started with vagrant</h2>
<p>&nbsp;</p>
<h3>Add a box to your vagrant installation</h3>
<p>Adding a box is as simple as:</p>
<pre><strong>[user@hostname ~]$</strong> vagrant box add &lt;boxname&gt; &lt;box path or url&gt;</pre>
<p>A box can be a local file, a remote file, &#8230;</p>
<p>For example:</p>
<pre><strong>[user@hostname ~]$</strong> vagrant box add centos-5.7 \

http://packages.vstone.eu/vagrant-boxes/centos-5.7-64bit-puppet-vbox.4.1.4.box</pre>
<p>Boxes are saved in ~/vagrant.d/boxes/. If you want them stored somewhere else on your disk, just remove the boxes folder and create a symlink to where whatever folder you prefer.</p>
<h3>Creating a vagrant environment</h3>
<p>Check what boxes you have available:</p>
<pre><strong>[user@hostname ~]$</strong> vagrant box list
centos-5.7-64bit</pre>
<pre>## create your 'project' structure.
<strong>[user@hostname ~]$</strong> mkdir -p example/{manifests,modules}
<strong>[user@hostname ~]$</strong> cd example
<strong>[user@hostname ~/example]$</strong> vagrant init &lt;boxname&gt;</pre>
<p>You can also run <code>vagrant init</code> without arguments in which case the box called &#8216;base&#8217; will be used. Adjusting the box to use can be done by altering the line:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">config.<span style="color:#9900CC;">vm</span>.<span style="color:#9900CC;">box</span> = <span style="color:#996600;">&quot;centos-5.7-64bit&quot;</span></pre></div></div>

<h3>Setting up your environment</h3>
<h4>Using puppet</h4>
<p>Before we get really started, we need to adjust our Vagrant file a bit. Uncomment or add the following sections:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">config.<span style="color:#9900CC;">vm</span>.<span style="color:#9900CC;">provision</span> <span style="color:#ff3333; font-weight:bold;">:puppet</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>puppet<span style="color:#006600; font-weight:bold;">|</span>
  puppet.<span style="color:#9900CC;">manifests_path</span> = <span style="color:#996600;">&quot;manifests&quot;</span>
  puppet.<span style="color:#9900CC;">module_path</span> = <span style="color:#996600;">&quot;modules&quot;</span>
  puppet.<span style="color:#9900CC;">manifest_file</span> = <span style="color:#996600;">&quot;init.pp&quot;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>This defines our module directory and our manifests folder. Puppet will run the init.pp (located in manifests folder) after booting the machine.</p>
<h4>Shared folders</h4>
<p>In some cases, it might also be useful to share an extra folder between your vm and machine.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">config.<span style="color:#9900CC;">vm</span>.<span style="color:#9900CC;">share_folder</span> <span style="color:#996600;">&quot;some_name&quot;</span>, <span style="color:#996600;">&quot;/mnt/on/vm/&quot;</span>, <span style="color:#996600;">&quot;/local/path/to/files&quot;</span></pre></div></div>

<h4>Tweaking your environment</h4>
<p>If you are a vim user and have enabled modeline support:</p>
<pre><strong>[user@hostname ~/example]$</strong> echo '# vim: set filetype=ruby : #' &gt;&gt; Vagrantfile</pre>
<p>Now is also a good time to introduce some version control. git is perfect for the job:</p>
<pre><strong>[user@hostname ~/example]$</strong> git init
Initialized empty Git repository in /home/user/example/.git/</pre>
<p>&nbsp;</p>
<h3>Starting up</h3>
<p>Starting your vm is as easy as:</p>
<pre><strong>[user@hostname ~/example]$</strong> vagrant up</pre>
<p>This will take some time. Vagrant copies (imports) the base box and starts the vm. The disk of the vm will be located in the &#8216;Default Machine Folder&#8217;. Sometimes its useful to tweak this location a bit. Use the VirtualBox GUI for this.</p>
<p>After booting, the init.pp puppet manifest will be run.</p>
<h3>Accessing your machine</h3>
<pre><strong>[user@hostname ~/example]$</strong> vagrant ssh</pre>
<p>You will be dropped in a shell. User is vagrant and there is a password-less sudo configured for this user.</p>
<h3>Hack *whack* hack!</h3>
<p>After changing, editing, &#8230; a manifest, you can use the following command to re-run puppet without rebooting the machine:</p>
<pre><strong>[user@hostname ~/example]$</strong> vagrant provision</pre>
<h3>Done!</h3>
<p>After you finished doing stuff, you can bring the machine down with:</p>
<pre><strong>[user@hostname ~/example]$</strong> vagrant destroy</pre>
<p>Keep in mind that all changes you made to the vm will be lost after this as vagrant will make a fresh copy of the base box when running <code>vagrant up</code>.</p>
]]></content:encoded>
			<wfw:commentRss>http://vstone.eu/vagrant-quickstart-for-puppet-devops/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

