Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How best to do this kinda depends on how you're managing the JDK install. Oftentimes this might mean that there's a specific directory, say /opt/java, under which any number of JDKs could be placed, where each JDK is a directory with a versioned name.

If that's how you're managing JDK one option for cleaning up older versions could be via the file resource itself. For example:

file { '/opt/java':
  ensure       => directory,
  owner        => 'root',
  group        => 'root',
  mode         => '0755',
  purge        => true,
  force        => true,
  recurse      => true,
  recurselimit => 1,
}

What this resource does is manage the /opt/java directory, and remove any files or directories created in it that aren't managed by Puppet. It only pays attention to files and directories directly in /opt/java; it ignores files in subdirectories.

Provided there is a file resource creating or managing the JDK version you want installed, Puppet will remove old versions automatically as soon as you remove them from Puppet management.

file { '/tmp/java/jdk-8u112':
  ensure => directory,
}

When you update your code to deploy the new version (however this is done, just using a trivialized example here):

file { '/tmp/java/jdk-8u162':
  ensure => directory,
}

...Puppet will remove old JDK directories that are no longer defined in Puppet code.