In my previous post I’ve explained how to setup Java on virtual machine using Puppet. Now it’s a time to make it for maven, basically most of the steps are the same.

1. Download maven archive.

Visit Apache Maven site and download recent binary tar gz archived maven version.

2. Create maven puppet module folders.

Execute following terminal command in your working directory:

Terminal Window
1
mkdir -p modules/maven/{files,manifests}

And copy downloaded maven binaries archive (apache-maven-3.1.0-bin.tar.gz in my case) into files sub-folder:

1
cp apache-maven-3.1.0-bin.tar.gz modules/maven/files/

3. Write down configuration script.

Create init.pp files inside manifests folder

Terminal Window
1
touch modules/maven/manifests/init.pp

Now let’s put there following implementation:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
class maven (
  $maven_home = "/usr/lib/maven",
  $maven_archive = "apache-maven-3.1.0-bin.tar.gz",
  $maven_folder = "apache-maven-3.1.0") {
  
  Exec {
      path => [ "/usr/bin", "/bin", "/usr/sbin"]
  }
  
  file { "/tmp/${maven_archive}":
      ensure => present,
      source => "puppet:///modules/maven/${maven_archive}",
      owner => vagrant,
      mode => 755,
  }
  
  exec { "extract maven":
      command => "tar xfv ${maven_archive}",
      cwd => "/tmp",
      creates => "${maven_home}",
      require => File["/tmp/${maven_archive}"]
  }

  exec { "move maven":
      command => "mv ${maven\_folder} ${maven_home}",
      creates => "${maven_home}",
      cwd => "/tmp",
      require => Exec["extract maven"]
  }
  
  file { "/etc/profile.d/maven.sh":
      content =>   "export MAVEN_HOME=${maven_home}
                   export M2=\$MAVEN_HOME/bin
                   export PATH=\$PATH:\$M2
                   export MAVEN_OPTS=\"-Xmx512m -Xms512m\""
  }
}

4. Put everything together.

I’ll continue to use Vagrantfile and manifest from previous post, therefore in order to test my new puppet script for maven install I’ll just use already create test_vm.pp and add following lines:

Terminal WIndow
1
echo "include maven" >> manifests/test_vm.pp

5. Reload VM (or start).

Terminal Window
1
vagrant reload test_vm

6. Enjoy!

In my next post I’ll finilize and put together current result with script from my previous post in order to implement scripts which will enable to setup Hadoop cluster on VM. Therefore all I’ve described in my first post could be easily automated.

PS. Here I’ve changed the puppet script same way as in my previous post, to support parametrized class definition to support customization.