<?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>Tapdancing Goats &#187; puppet</title>
	<atom:link href="http://www.tapdancinggoats.com/tag/puppet/feed" rel="self" type="application/rss+xml" />
	<link>http://www.tapdancinggoats.com</link>
	<description>A parfait of physics, Linux, LaTeX, and coding tips large and small.</description>
	<lastBuildDate>Wed, 25 Jan 2012 03:14:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Server Variables in Puppet Templates</title>
		<link>http://www.tapdancinggoats.com/server-variables-in-puppet-templates.htm</link>
		<comments>http://www.tapdancinggoats.com/server-variables-in-puppet-templates.htm#comments</comments>
		<pubDate>Mon, 01 Mar 2010 05:01:09 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[erb]]></category>
		<category><![CDATA[puppet]]></category>

		<guid isPermaLink="false">http://www.tapdancinggoats.com/?p=455</guid>
		<description><![CDATA[Puppet is an invaluable tool for managing a large number of Linux servers. By defining different classes for each service I deploy, I can easily define what runs on each server I control just by changing the site manifest. A problem I ran into early when I was bringing services into Puppet was slightly different [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.reductivelabs.com/trac/puppet/" title="Puppet">Puppet</a> is an <a href="http://www.tapdancinggoats.com/make-your-servers-dance-with-puppet.htm" title="Make your Linux servers dance with Puppet">invaluable tool</a> for managing a large number of Linux servers. By defining different classes for each service I deploy, I can easily define what runs on each server I control just by changing the site manifest.</p>

<p>A problem I ran into early when I was bringing services into Puppet was slightly different configurations on servers with different specs. For example, I run <a href="http://tomcat.apache.org/" title="Tomcat Java Servlet Engine">Tomcat</a> on three servers but one is also running some other services. On this one server the JVM maximum heap size needs to be lower than on the others, but the rest of the Tomcat configuration is the same. To manage this without making a second class definition I used the template system in Puppet.</p>

<p>There are four steps to making this work. First you need to define a default for the variable. Next you need to write the template. Third, connect the template to a file on the client. Finally override the variable where you need it.</p>

<p><span id="more-455"></span></p>

<h4>Define a default</h4>

<p>The default variable definition goes in the module&#8217;s manifest file <em>before</em> the class definition. Putting it before the class definition makes sure that it is in scope for overriding in the node definition. The top of the manifest file will look like this:</p>

<pre><code>$heapsize = 1000

class jvm {
...
</code></pre>

<p>Note that variables have leading dollar signs.</p>

<h4>Write the template</h4>

<p>Puppet uses Ruby&#8217;s <a href="http://ruby-doc.org/stdlib/libdoc/erb/rdoc/classes/ERB.html" title="ERB Documentation">ERB</a> templating system. The template language is powerful, but I&#8217;m only going to cover variable substitution here.</p>

<p>Start with putting the configuration file in the templates subdirectory of the module, i.e. <em>&lt;module name&gt;/templates/&lt;config&gt;</em> so that Puppet knows where to find it. To substitute the variables, use <em>< %= name %></em>. Here the variable name <em>does not</em> start with a dollar sign. Continuing the earlier example, this is part of our template:</p>

<pre><code>export JAVA_OPTS="-Xmx&lt;%= heapsize %&gt;M"
</code></pre>

<h4>Connecting the template to a file</h4>

<p>Using the template in a file declaration is not as simple as just changing the path from the static source. Instead, you have to use the <em>content</em> parameter and the <em>template</em> function. The parameter to the template function is a weird path fragment: the first segment is the module name, and the rest is the path to your file underneath the templates directory. Continuing our example, assuming that the module is named <em>jvm</em> and the template is at <em>modules/jvm/templates/options.erb</em>, this declaration is in the jvm class:</p>

<pre><code>file {"/usr/local/bin/jvm_options.sh":
mode    =&gt; "664",
content =&gt; template("jvm/options.erb"),
}
</code></pre>

<p>Notice that the name of the template file doesn&#8217;t have to match the target name on the client.</p>

<h4>Override the variable</h4>

<p>Finally, you have to add a line to the node for the server which needs a different configuration. In the node definition before including the class, redefine the variable to what you need. Example:</p>

<pre><code>node "lowmem" {
$heapsize = 750
include jvm
}
</code></pre>

<p>Nodes that don&#8217;t override the variable will get the default value defined in the module&#8217;s manifest file.</p>

<p>Puppet&#8217;s templates can do a lot more than simple variable substitution, but this should get you started. Beyond this it&#8217;s mostly <a href="http://ruby-doc.org/stdlib/libdoc/erb/rdoc/classes/ERB.html" title="ERB Documentation">ERB</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tapdancinggoats.com/server-variables-in-puppet-templates.htm/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Make your Linux servers dance with Puppet</title>
		<link>http://www.tapdancinggoats.com/make-your-servers-dance-with-puppet.htm</link>
		<comments>http://www.tapdancinggoats.com/make-your-servers-dance-with-puppet.htm#comments</comments>
		<pubDate>Wed, 17 Feb 2010 22:12:45 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[OSS]]></category>
		<category><![CDATA[cluster]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[puppet]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://www.tapdancinggoats.com/?p=444</guid>
		<description><![CDATA[A quick introduction to Puppet, a system for replicating configurations to many Linux servers.]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.flickr.com/photos/quitepeculiar/3946841381/"><img src="http://www.tapdancinggoats.com/wp-content/uploads/2010/02/puppet.jpg" alt="" title="Marionette" width="160" height="240" class="alignright size-full wp-image-448" /></a><a href="http://reductivelabs.com/trac/puppet/" title="Puppet">Puppet</a> is a system for replicating configurations to many servers, and it makes managing a Linux<sup id="fnref:2"><a href="#fn:2" rel="footnote">1</a></sup> server farm ridiculously easy. One server runs a master process, while the others run a client which connects to the master<sup id="fnref:1"><a href="#fn:1" rel="footnote">2</a></sup> to get the correct configuration. Clients are identified by hostname, so if your servers don&#8217;t have resolvable names you&#8217;ll need to put them in the hosts file on the master.</p>

<p>Puppet uses a declarative syntax built on top of ruby for defining rules. The documentation is mediocre at best, so you may struggle at first learning how to write the rules. Just read through the example recipes and test it out with a non-production server. The easiest way I found to test a rule is to run</p>

<pre><code>sudo puppetd --test
</code></pre>

<p>on the server that should be getting the configuration. It will tell you there if there are any errors.</p>

<p>The version of puppet in Ubuntu 9.10 doesn&#8217;t support defining node names with regular expressions, so you might want to grab the <a href="http://packages.debian.org/sid/puppet" title="Puppet package">version in Debian sid</a>.</p>

<p>I&#8217;m still trying to figure out the best way to split up modules and organize my node definitions, so if you&#8217;ve used Puppet leave a comment and let me know what you think.</p>

<div class="footnotes">
<hr />
<ol>

<li id="fn:2">
<p>The <a href="http://www.reductivelabs.com/trac/puppet/wiki/DownloadingPuppet" title="Download Puppet">website</a> also has packages for BSD and MacOS, but I can&#8217;t vouch for them.&#160;<a href="#fnref:2" rev="footnote">&#8617;</a></p>
</li>

<li id="fn:1">
<p>By default the clients connect to a host named puppet, so you should either make an DNS entry for your master, or define the name puppet in your clients&#8217; hosts files.&#160;<a href="#fnref:1" rev="footnote">&#8617;</a></p>
</li>

</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.tapdancinggoats.com/make-your-servers-dance-with-puppet.htm/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

