Ask Your Question
0

One module to install several versions of software

asked 2015-02-25 04:03:53 -0500

Geir gravatar image

Hi!

I have created a module named openjdk and I want it to support installation of several openjdk versions. Like for instance in the node definition,

node www01 {
  class { "::openjdk":
    versions    => [ '7', '8' ],
  }

The module don't seem to 'get' the version numbers I send along in the node-definition, which is my first problem. Also, I would like this module to iterate through the different packets so if I send along version '7' and '8' in the node definition, the module will install both.

This is my modules init.pp

class openjdk (
  $versions = $openjdk::params::versions
) inherits openjdk::params {
  validate_array($versions)

  anchor { 'openjdk::begin': } ->
  class { '::openjdk::install': } ->
  anchor { 'openjdk::end': }
}

This is my params.pp

class openjdk::params {
  $versions    = []
  case $::osfamily {
    FreeBSD: {
      $package_name = [ "openjdk-$versions" ]
    }
  }
}

And finally my install.pp

class openjdk::install inherits openjdk {
  if ! ($versions) {
    fail("You didn't provide any jdk versions to be installed")
  } 
  package { $package_name:
    ensure  => present,
  }  
}

Any help would be very much appreciated! :)

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2015-02-25 11:16:49 -0500

GregLarkin gravatar image

updated 2015-02-26 15:43:59 -0500

Can you describe what you mean by the "module doesn't get the version numbers"? Is your variable $versions always an empty array inside your module code?

Next, I would install the puppetlabs/stdlib module on your master and update your install.pp class like so:

class openjdk::install inherits openjdk {
  if ! ($versions) {
    fail("You didn't provide any jdk versions to be installed")
  } 

  # stdlib function to convert [ '7', '8' ] to [ 'openjdk7', 'openjdk8' ]
  $package_names = prefix($versions, 'openjdk')

  package { [ $package_names ]:
    ensure  => present,
  }  
}

It's been a while since I used FreeBSD, but this also assumes it's legal to install the openjdk7 and openjdk8 packages on the same machine at the same time.

UPDATE:

Here is a working example with a few different tests included. The main thing I did was change the params.pp to include a sane default for the openjdk package version. If you set $versions to an empty array, that causes various problems, so you want to set it to something valid.

https://gist.github.com/greglarkin/e4be053ec3a4a37fb444

Hope that helps!

edit flag offensive delete link more

Comments

Yes correct, the $versions variable is always empty inside my module code (unless i define it inside the params.pp, obviously). Thanks for the tip! I'll definitively take it to use! But I think I'll put the prefix function into my params.pp file where it logically belongs :)

Geir gravatar imageGeir ( 2015-02-26 01:02:31 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2015-02-25 04:03:53 -0500

Seen: 148 times

Last updated: Feb 26 '15