Mark Needham

Thoughts on Software Development

Puppet: Installing Oracle Java – oracle-license-v1-1 license could not be presented

with 5 comments

In order to run the neo4j server on my Ubuntu 12.04 Vagrant VM I needed to install the Oracle/Sun JDK which proved to be more difficult than I’d expected.

I initially tried to install it via the OAB-Java script but was running into some dependency problems and eventually came across a post which specified a PPA that had an installer I could use.

I wrote a little puppet Java module to wrap the commands in:

class java($version) {
  package { "python-software-properties": }
 
  exec { "add-apt-repository-oracle":
    command => "/usr/bin/add-apt-repository -y ppa:webupd8team/java",
    notify => Exec["apt_update"]
  }
 
  package { 'oracle-java7-installer':
    ensure => "${version}",
    require => [Exec['add-apt-repository-oracle']],
  }
}

I then included this in my default node definition:

node default {
  class { 'java': version => '7u21-0~webupd8~0', }
}

(as Dave Yeung points out in the comments, you may need to tweak the version. Running aptitude versions oracle-java7-installer should indicate the latest version.)

Unfortunately when I ran that I ended up with the following error:

err: /Stage[main]/Java/Package[oracle-java7-installer]/ensure: change from purged to present failed: Execution of '/usr/bin/apt-get -q -y -o DPkg::Options::=--force-confold install oracle-java7-installer' returned 100: Reading package lists...
Building dependency tree...
Reading state information...
The following extra packages will be installed:
  java-common
Suggested packages:
...
Unpacking oracle-java7-installer (from .../oracle-java7-installer_7u21-0~webupd8~0_all.deb) ...
 
oracle-license-v1-1 license could not be presented
try 'dpkg-reconfigure debconf' to select a frontend other than noninteractive
 
dpkg: error processing /var/cache/apt/archives/oracle-java7-installer_7u21-0~webupd8~0_all.deb (--unpack):
 subprocess new pre-installation script returned error exit status 2
Processing triggers for man-db ...
Errors were encountered while processing:
 /var/cache/apt/archives/oracle-java7-installer_7u21-0~webupd8~0_all.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

I came across this post on Ask Ubuntu which explained a neat trick for getting around it by making it look like we’ve agreed to the licence. This is done by passing options to debconf-set-selections.

For a real server I guess you’d want some step where a person accepts the licence but since this is just for my hacking it seems to make sense.

My new Java manifest looks like this:

class java($version) {
  package { "python-software-properties": }
 
  exec { "add-apt-repository-oracle":
    command => "/usr/bin/add-apt-repository -y ppa:webupd8team/java",
    notify => Exec["apt_update"]
  }
 
  exec {
    'set-licence-selected':
      command => '/bin/echo debconf shared/accepted-oracle-license-v1-1 select true | /usr/bin/debconf-set-selections';
 
    'set-licence-seen':
      command => '/bin/echo debconf shared/accepted-oracle-license-v1-1 seen true | /usr/bin/debconf-set-selections';
  }
 
  package { 'oracle-java7-installer':
    ensure => "${version}",
    require => [Exec['add-apt-repository-oracle'], Exec['set-licence-selected'], Exec['set-licence-seen']],
  }
}
Be Sociable, Share!

Written by Mark Needham

April 18th, 2013 at 11:36 pm

Posted in DevOps

Tagged with ,

  • Fabio Rauber

    Thanks a lot for this!

  • yeungda

    Note to future self. The version that works today is different to the one that worked when the post was written. A missing version results in the error:

    Error: Could not update: Execution of ‘/usr/bin/apt-get -q -y -o DPkg::Options::=–force-confold –force-yes install oracle-java7-installer=7u21-0~webupd8~0′ returned 100: Reading package lists…
    Building dependency tree…
    Reading state information…
    E: Version ’7u21-0~webupd8~0′ for ‘oracle-java7-installer’ was not found

    The remedy is to find out the version:

    aptitude versions oracle-java7-installer

    Package oracle-java7-installer:
    p 7u40-0~webupd8~0

    and update the script.

  • http://www.markhneedham.com/blog Mark Needham

    @7faabbc78dff97e8058b1d90d4031d9a:disqus nice one. I’ve updated the post to take that into account.

  • greg.1.anderson

    It is not necessary to specifically query for the exact version to use; if you pass in ‘latest’ as your desired version, then ensure => “latest” will cause the package class to install the most recent version available in the ppa.

  • Slava Semushin

    Thanks for sharing this tip. It works! Also I don’t need executing of

    `set-licence-seen` command. And to stop executing these commands each time I added `unless` attribute:

    unless => “test “$(debconf-get-selections | grep ‘oracle-java7-installer\s\+shared/accepted-oracle-license-v1-1′ | awk ‘{print $4}’)” = ‘true’”