<?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>Puppet &#8211; My Shitty Code</title>
	<atom:link href="https://myshittycode.com/tag/puppet/feed/" rel="self" type="application/rss+xml" />
	<link>https://myshittycode.com</link>
	<description>Embracing the Messiness in Search of Epic Solutions</description>
	<lastBuildDate>Fri, 06 Jan 2023 17:10:33 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.1</generator>

<image>
	<url>https://myshittycode.com/wp-content/uploads/2022/04/cropped-icon-32x32.png</url>
	<title>Puppet &#8211; My Shitty Code</title>
	<link>https://myshittycode.com</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">205304208</site>	<item>
		<title>Puppet: Installing Multiple Java Versions On Single Node</title>
		<link>https://myshittycode.com/2014/03/02/puppet-installing-multiple-java-versions-on-single-node/</link>
					<comments>https://myshittycode.com/2014/03/02/puppet-installing-multiple-java-versions-on-single-node/#comments</comments>
		
		<dc:creator><![CDATA[Shitty Author]]></dc:creator>
		<pubDate>Sun, 02 Mar 2014 18:19:25 +0000</pubDate>
				<category><![CDATA[Programming Language]]></category>
		<category><![CDATA[Development Tools]]></category>
		<category><![CDATA[Operating System]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Puppet]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<guid isPermaLink="false">http://myshittycode.com/?p=369</guid>

					<description><![CDATA[<p>PROBLEM I couldn&#8217;t find an existing Puppet module that allows me to install multiple Java versions on a single node. The reason for multiple Java versions is to allow Jenkins&#8217;s jobs to choose what Java version to compile with. So, I will show you how to create a Puppet module that will do just that. [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://myshittycode.com/2014/03/02/puppet-installing-multiple-java-versions-on-single-node/">Puppet: Installing Multiple Java Versions On Single Node</a> appeared first on <a rel="nofollow" href="https://myshittycode.com">My Shitty Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading">PROBLEM</h2>



<p>I couldn&#8217;t find an existing Puppet module that allows me to install multiple Java versions on a single node. The reason for multiple Java versions is to allow Jenkins&#8217;s jobs to choose what Java version to compile with.</p>



<p>So, I will show you how to create a Puppet module that will do just that.</p>



<h2 class="wp-block-heading">PREREQUISITES</h2>



<ul class="wp-block-list">
<li>This script is tailored to run on Ubuntu.</li>



<li>Install <a href="http://myshittycode.com/2014/03/01/installing-puppet-v3-2-in-ubuntu/" target="_blank" rel="noopener">Puppet v3.2+</a> because this script uses lambdas.</li>



<li>Install <a href="https://forge.puppetlabs.com/puppetlabs/apt" target="_blank" rel="noopener">puppetlabs/apt</a>. It should indirectly install <a href="https://forge.puppetlabs.com/puppetlabs/stdlib" target="_blank" rel="noopener">puppetlabs/stdlib</a>.</li>
</ul>



<p>The Puppet file structure should look like this:-</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
/etc/puppet/
├── hiera.yaml
├── manifests
│   └── site.pp
├── modules
│   ├── apt
│   └── stdlib
├── puppet.conf
└── templates
</pre></div>


<p>If you don&#8217;t have <b>/etc/puppet/hiera.yaml</b>, create one. Otherwise, you will get this annoying warning message:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
Warning: Config file /etc/puppet/hiera.yaml not found, using Hiera defaults
</pre></div>


<p>My <b>/etc/puppet/hiera.yaml</b> looks like this:-</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: yaml; title: ; notranslate">
---
:backends:
  - yaml

:logger: console

:hierarchy:
  - &quot;%{operatingsystem}&quot;
  - common

:yaml:
   :datadir: /etc/puppet/hieradata
</pre></div>


<h2 class="wp-block-heading">CREATING JAVA MODULE</h2>



<p>Now, we are ready to create a Java module.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; highlight: [7,8,9,10,11]; title: ; notranslate">
/etc/puppet/
├── hiera.yaml
├── manifests
│   └── site.pp
├── modules
│   ├── apt
│   ├── java
│   │   ├── files
│   │   │   └── java.preseed
│   │   └── manifests
│   │       └── init.pp
│   └── stdlib
├── puppet.conf
└── templates
</pre></div>


<h3 class="wp-block-heading">Creating <b>/etc/puppet/modules/java/files/java.preseed</b></h3>



<p>The preseed file contains the responses needed to programmatically configure the package. In this module, I configured all the responses needed to install Java 6, 7 and 8.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
oracle-java6-installer	shared/present-oracle-license-v1-1    note
oracle-java6-installer	oracle-java6-installer/local          string
oracle-java6-installer	shared/accepted-oracle-license-v1-1   boolean   true


oracle-java7-installer  shared/present-oracle-license-v1-1    note
oracle-java7-installer  oracle-java7-installer/local          string
oracle-java7-installer  shared/accepted-oracle-license-v1-1   boolean   true

oracle-java8-installer  shared/present-oracle-license-v1-1    note
oracle-java8-installer  oracle-java8-installer/local          string
oracle-java8-installer  shared/accepted-oracle-license-v1-1   boolean   true
</pre></div>


<p>If you are wondering how I figured out these values, you can easily <a href="http://projects.puppetlabs.com/projects/1/wiki/debian_preseed_patterns" target="_blank" rel="noopener">generate a response file by manually installing a package first</a>.</p>



<h3 class="wp-block-heading">Creating <b>/etc/puppet/modules/java/manifests/init.pp</b></h3>



<p>This is the actual script that will perform the following tasks:-</p>



<ul class="wp-block-list">
<li>Remove all OpenJDK versions if they exist.</li>



<li>Install multiple Oracle Java versions.</li>



<li>Select a default Java version.</li>
</ul>



<p>If none of the arguments are provided, this script will install Java 7 and set it as the default version.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: ruby; title: ; notranslate">
class java (
  $versions = &#x5B;7],
  $default_version = 7
) {

  include apt

  apt::ppa{ &#039;ppa:webupd8team/java&#039;: }

  each( &#x5B;6,7,8] ) | $version | {
    package { &#x5B;&quot;openjdk-${version}-jdk&quot;, &quot;openjdk-${version}-jre&quot;]:
      ensure =&amp;gt; &#039;purged&#039;,
    }
  }

  file { &quot;/tmp/java.preseed&quot;:
    source =&gt; &quot;puppet:///modules/java/java.preseed&quot;,
    mode   =&gt; &#039;0600&#039;,
    backup =&gt; false,
  }

  each( $versions ) | $version | {
    package { &quot;oracle-java${version}-installer&quot;:
      responsefile =&gt; &quot;/tmp/java.preseed&quot;,
      require      =&gt; &#x5B;
        Apt::Ppa&#x5B;&#039;ppa:webupd8team/java&#039;],
        File&#x5B;&quot;/tmp/java.preseed&quot;]
      ],
    }
  }

  exec{ &quot;update-java-alternatives -s java-${default_version}-oracle&quot;:
    path    =&gt; &#x5B;&quot;/usr/bin&quot;, &quot;/usr/sbin&quot;],
    require =&gt; Package&#x5B;&quot;oracle-java${default_version}-installer&quot;],
  }
}
</pre></div>


<h3 class="wp-block-heading">Creating <b>/etc/puppet/manifests/site.pp</b></h3>



<p>In this example, we will install Java 6, Java 7 and Java 8. Further, we will set Java 7 to be the default version.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: ruby; title: ; notranslate">
node default {
  class { &#039;java&#039;:
    versions        =&gt;; &#x5B;6,7,8],
    default_version =&gt; 7,
  }
}
</pre></div>


<h2 class="wp-block-heading">TESTING</h2>



<p>By specifying <b>&#8211;noop</b>, Puppet will execute the script in dry-run mode without applying the changes. This is very useful to catch any syntax errors before running the script for real. Since this script uses lambdas, we need to add <b>&#8211;parser future</b> option.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
ubuntu@test:/$ sudo puppet apply --parser future --noop /etc/puppet/manifests/site.pp
Notice: Compiled catalog for test.mayo.edu in environment production in 1.32 seconds
Notice: /Stage&#x5B;main]/Java/Package&#x5B;oracle-java6-installer]/ensure: current_value absent, should be present (noop)
Notice: /Stage&#x5B;main]/Java/Package&#x5B;oracle-java8-installer]/ensure: current_value absent, should be present (noop)
Notice: /Stage&#x5B;main]/Java/Package&#x5B;oracle-java7-installer]/ensure: current_value absent, should be present (noop)
Notice: /Stage&#x5B;main]/Java/Exec&#x5B;update-java-alternatives -s java-7-oracle]/returns: current_value notrun, should be 0 (noop)
Notice: Class&#x5B;Java]: Would have triggered &#039;refresh&#039; from 4 events
Notice: Stage&#x5B;main]: Would have triggered &#039;refresh&#039; from 1 events
Notice: Finished catalog run in 1.57 seconds
</pre></div>


<h2 class="wp-block-heading">EXECUTION</h2>



<p>To apply the changes on the node, simply remove <b>&#8211;noop</b>.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
ubuntu@test:/$ sudo puppet apply --parser future /etc/puppet/manifests/site.pp
Notice: Compiled catalog for test.mayo.edu in environment production in 1.31 seconds
Notice: /Stage&#x5B;main]/Java/Package&#x5B;oracle-java6-installer]/ensure: created
Notice: /Stage&#x5B;main]/Java/Package&#x5B;oracle-java8-installer]/ensure: created
Notice: /Stage&#x5B;main]/Java/Package&#x5B;oracle-java7-installer]/ensure: created
Notice: /Stage&#x5B;main]/Java/Exec&#x5B;update-java-alternatives -s java-7-oracle]/returns: executed successfully
Notice: Finished catalog run in 97.06 seconds
</pre></div>


<h2 class="wp-block-heading">VERIFICATION</h2>



<p>First, we check if all 3 Java versions are installed.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
ubuntu@test:/$ ls -la /usr/lib/jvm/
total 32
drwxr-xr-x  5 root root 4096 Mar  2 17:59 .
drwxr-xr-x 63 root root 4096 Mar  2 17:59 ..
drwxr-xr-x  8 root root 4096 Mar  2 17:58 java-6-oracle
-rw-r--r--  1 root root 2430 Mar  2 17:58 .java-6-oracle.jinfo
drwxr-xr-x  8 root root 4096 Mar  2 17:59 java-7-oracle
-rw-r--r--  1 root root 2583 Mar  2 17:59 .java-7-oracle.jinfo
drwxr-xr-x  8 root root 4096 Mar  2 17:59 java-8-oracle
-rw-r--r--  1 root root 2481 Mar  2 17:59 .java-8-oracle.jinfo
</pre></div>


<p>Finally, we check if the right default Java version is set.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
ubuntu@test:/$ java -version
java version &quot;1.7.0_51&quot;
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)
</pre></div>

<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
ubuntu@test:/$ javac -version
javac 1.7.0_51
</pre></div><p>The post <a rel="nofollow" href="https://myshittycode.com/2014/03/02/puppet-installing-multiple-java-versions-on-single-node/">Puppet: Installing Multiple Java Versions On Single Node</a> appeared first on <a rel="nofollow" href="https://myshittycode.com">My Shitty Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://myshittycode.com/2014/03/02/puppet-installing-multiple-java-versions-on-single-node/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">369</post-id>	</item>
		<item>
		<title>Installing Puppet v3.2+ in Ubuntu</title>
		<link>https://myshittycode.com/2014/03/01/installing-puppet-v3-2-in-ubuntu/</link>
					<comments>https://myshittycode.com/2014/03/01/installing-puppet-v3-2-in-ubuntu/#comments</comments>
		
		<dc:creator><![CDATA[Shitty Author]]></dc:creator>
		<pubDate>Sun, 02 Mar 2014 03:32:34 +0000</pubDate>
				<category><![CDATA[Development Tools]]></category>
		<category><![CDATA[Operating System]]></category>
		<category><![CDATA[Puppet]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<guid isPermaLink="false">http://myshittycode.com/?p=366</guid>

					<description><![CDATA[<p>PROBLEM By default, when using apt-get, Puppet v2.7 will be installed. This version doesn&#8217;t support useful features, such as Lambdas and iteration. To use these experimental features, Puppet v3.2+ is required. SOLUTION First, visit http://apt.puppetlabs.com/ and determine the matching Ubuntu version. Let&#8217;s assume we are using Ubuntu 13.04 (Raring Ringtail). So, we will choose http://apt.puppetlabs.com/puppetlabs-release-raring.deb [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://myshittycode.com/2014/03/01/installing-puppet-v3-2-in-ubuntu/">Installing Puppet v3.2+ in Ubuntu</a> appeared first on <a rel="nofollow" href="https://myshittycode.com">My Shitty Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading">PROBLEM</h2>



<p>By default, when using <b>apt-get</b>, Puppet v2.7 will be installed. This version doesn&#8217;t support useful features, such as Lambdas and iteration. To use these experimental features, <a href="http://docs.puppetlabs.com/puppet/3/reference/experiments_future.html" target="_blank" rel="noopener">Puppet v3.2+</a> is required.</p>



<h2 class="wp-block-heading">SOLUTION</h2>



<p>First, visit http://apt.puppetlabs.com/ and determine the matching Ubuntu version.</p>



<p>Let&#8217;s assume we are using Ubuntu 13.04 (Raring Ringtail). So, we will choose http://apt.puppetlabs.com/puppetlabs-release-raring.deb from the list.</p>



<p>Execute the following commands to install Puppet:-</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
wget http://apt.puppetlabs.com/puppetlabs-release-raring.deb
sudo dpkg -i puppetlabs-release-raring.deb
sudo apt-get update
sudo apt-get install puppet
</pre></div>


<p>Finally, run the following command to verify the installed version:-</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
puppet --version
</pre></div>


<p>The installed version should be v3.2+ and above.</p>
<p>The post <a rel="nofollow" href="https://myshittycode.com/2014/03/01/installing-puppet-v3-2-in-ubuntu/">Installing Puppet v3.2+ in Ubuntu</a> appeared first on <a rel="nofollow" href="https://myshittycode.com">My Shitty Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://myshittycode.com/2014/03/01/installing-puppet-v3-2-in-ubuntu/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">366</post-id>	</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/?utm_source=w3tc&utm_medium=footer_comment&utm_campaign=free_plugin

Page Caching using Disk: Enhanced 
Lazy Loading (feed)
Database Caching using Disk

Served from: myshittycode.com @ 2026-02-18 19:25:35 by W3 Total Cache
-->