Skip to content

Instantly share code, notes, and snippets.

@renoirb
Last active March 30, 2023 03:15
Show Gist options
  • Star 23 You must be signed in to star a gist
  • Fork 8 You must be signed in to fork a gist
  • Save renoirb/6722890 to your computer and use it in GitHub Desktop.
Save renoirb/6722890 to your computer and use it in GitHub Desktop.
How to install Oracle Java from ppa webupd8team/java using Salt stack, in ONE state file
#
# How to install automatically Oracle Java 7 under Salt Stack
#
# Thanks Oracle for complicating things :(
#
# 1. Create a java/ folder in your salt master
# 2. Paste this file in init.sls
# 3. salt '*' state.sls java
#
# Source:
# * https://github.com/log0ymxm/salt-jvm/blob/master/init.sls
# * http://architects.dzone.com/articles/puppet-installing-oracle-java
#
oracle-ppa:
pkgrepo.managed:
- humanname: WebUpd8 Oracle Java PPA repository
- ppa: webupd8team/java
oracle-license-select:
cmd.run:
- unless: which java
- name: '/bin/echo /usr/bin/debconf shared/accepted-oracle-license-v1-1 select true | /usr/bin/debconf-set-selections'
- require_in:
- pkg: oracle-java7-installer
- cmd: oracle-license-seen-lie
oracle-license-seen-lie:
cmd.run:
- name: '/bin/echo /usr/bin/debconf shared/accepted-oracle-license-v1-1 seen true | /usr/bin/debconf-set-selections'
- require_in:
- pkg: oracle-java7-installer
oracle-java7-installer:
pkg:
- installed
- require:
- pkgrepo: oracle-ppa
@igo
Copy link

igo commented Oct 11, 2013

There is a typo bug. ppa should be webupd8team/java

@renoirb
Copy link
Author

renoirb commented Nov 1, 2013

Thanks for the typo

@ssbarnea
Copy link

ssbarnea commented Nov 6, 2013

Hi Igo and thanks for posting this, I was looking to do the the same thing for salt. Still, it seems that your yml is not working for me. I run it agains a debian machine and I got:

---------
    State: - pkgrepo
    Name:      oracle-ppa
    Function:  managed
        Result:    False
        Comment:   Failed to confirm config of repo oracle-ppa: repo "oracle-ppa" was not found
        Changes:
----------
    State: - cmd
    Name:      /bin/echo /usr/bin/debconf shared/accepted-oracle-license-v1-1 select true | /usr/bin/debconf-set-selections
    Function:  run
        Result:    True
        Comment:   Command "/bin/echo /usr/bin/debconf shared/accepted-oracle-license-v1-1 select true | /usr/bin/debconf-set-selections" run
        Changes:   pid: 27114
                   retcode: 0
                   stderr:
                   stdout:

----------
    State: - cmd
    Name:      /bin/echo /usr/bin/debconf shared/accepted-oracle-license-v1-1 seen true  | /usr/bin/debconf-set-selections
    Function:  run
        Result:    True
        Comment:   Command "/bin/echo /usr/bin/debconf shared/accepted-oracle-license-v1-1 seen true  | /usr/bin/debconf-set-selections" run
        Changes:   pid: 27118
                   retcode: 0
                   stderr:
                   stdout:

----------
    State: - pkg
    Name:      oracle-java7-installer
    Function:  installed
        Result:    False
        Comment:   One or more requisite failed
        Changes:

Summary
------------
Succeeded: 2
Failed:    2
------------
Total:     4

@pwistrand
Copy link

It doesn't work on Debian as far as I can tell because the ppa argument is for ubuntu only (see the docs http://docs.saltstack.com/ref/states/all/salt.states.pkgrepo.html)

@geekpete
Copy link

Have you tried using the built in salt debconf functionality to set that acceptance?

oracle-java-license-autoaccept:
  debconf.set:
    - name: oracle-java7-installer
    - data:
        'shared/accepted-oracle-license-v1-1': {'type': 'boolean', 'value': True}

@geekpete
Copy link

A possible solution to the ubuntu/debian ppa might be:

java-ppa:
  {% if grains['os'] == 'Ubuntu' %}
  pkgrepo.managed:
    - ppa: webupd8team/java
  {% elif grains['os'] == 'Debian' %}
  pkgrepo.managed:
    - humanname: webup8team
    - name: deb http://ppa.launchpad.net/webupd8team/java/ubuntu precise main
    - dist: precise
    - file: /etc/apt/sources.list.d/webup8team.list
    - keyid: EEA14886
    - keyserver: keyserver.ubuntu.com
  {% endif %}

@rasathus
Copy link

I'll second geekpete's addition, with the addition of a require_in. By using the salt debconf.set the current state is checked, and so it doesnt trigger an update on each highstate run.

oracle-java-license-autoaccept:
  debconf.set:
    - name: oracle-java7-installer
    - data:
        'shared/accepted-oracle-license-v1-1': {'type': 'boolean', 'value': True}
    - require_in:
      - pkg: oracle-java7-installer

@ipmb
Copy link

ipmb commented Jul 31, 2014

Here's a concise option incorporating the suggestions (for Ubuntu):

oracle-java7-installer:
  pkgrepo.managed:
    - ppa: webupd8team/java
  pkg.installed:
    - require:
      - pkgrepo: oracle-java7-installer
  debconf.set:
    - data:
        'shared/accepted-oracle-license-v1-1': {'type': 'boolean', 'value': True}
    - require_in:
      - pkg: oracle-java7-installer

@Reiner030
Copy link

Here my adopted working version for Debian Wheezy (and Ubuntu):

{% set java_version = salt['pillar.get']('java_version', '8') %}

oracle-java{{ java_version }}-installer:
  {% if grains['os'] == 'Ubuntu' %}
  pkgrepo.managed:
    - ppa: webupd8team/java
  {% elif grains['os'] == 'Debian' %}
  pkgrepo.managed:
    - humanname: WebUp8Team Java Repository
    - name: "deb http://ppa.launchpad.net/webupd8team/java/ubuntu precise main"
    - dist: precise
    - file: /etc/apt/sources.list.d/webup8team.list
    - keyid: EEA14886
    - keyserver: keyserver.ubuntu.com
  {% endif %}
  pkg.installed:
    - require:
      - pkgrepo: oracle-java{{ java_version }}-installer
  debconf.set:
   - data:
       'shared/accepted-oracle-license-v1-1': {'type': 'boolean', 'value': True}
   - require_in:
       - pkg: oracle-java{{ java_version }}-installer

@JensRantil
Copy link

If you run into issues with the PPA not being picked up after upgrading to 2014.7.0, see here.

@JensRantil
Copy link

java-ppa:
  {% if grains['os'] == 'Ubuntu' %}
  pkgrepo.managed:
    - ppa: webupd8team/java
  {% elif grains['os'] == 'Debian' %}
  pkgrepo.managed:
    - humanname: webup8team
    - name: deb http://ppa.launchpad.net/webupd8team/java/ubuntu precise main
    - dist: precise
    - file: /etc/apt/sources.list.d/webup8team.list
    - keyid: EEA14886
    - keyserver: keyserver.ubuntu.com
  {% endif %}

@geekpete Is there any reason why you aren't simply skipping the Ubuntu case above? The Debian case should cover them both, right?

@JensRantil
Copy link

FYI, the Debian case seem to work also on Ubuntu.

@shofetim
Copy link

You might also need to install debconf-utils to get the debconf state. Also I prefer to require that all data comes from pillar, no defaults:

debconf-utils:
  pkg.installed

oracle-java{{ pillar['java_version'] }}-installer:
  pkgrepo.managed:
    - humanname: WebUp8Team Java Repository
    - name: "deb http://ppa.launchpad.net/webupd8team/java/ubuntu precise main"
    - dist: precise
    - file: /etc/apt/sources.list.d/webup8team.list
    - keyid: EEA14886
    - keyserver: keyserver.ubuntu.com
  pkg.installed:
    - require:
      - pkgrepo: oracle-java{{ pillar['java_version'] }}-installer
  debconf.set:
   - data:
       'shared/accepted-oracle-license-v1-1': {'type': 'boolean', 'value': True}
   - require_in:
       - pkg: oracle-java{{ pillar['java_version'] }}-installer

Tested on Debian Wheezy

@JJ
Copy link

JJ commented Oct 2, 2016

I seem to be getting an error here:

          ID: oracle-ppa
    Function: pkgrepo.managed
      Result: False
     Comment: Failed to examine repo 'oracle-ppa': Error: 'python-apt' package not installed

Do I need to install python-apt before?

@cprima
Copy link

cprima commented Dec 25, 2016

On http://www.webupd8.org/2014/03/how-to-install-oracle-java-8-in-debian.html ist says:

Update October 20, 2016:
...
So, if you want to set Oracle Java 8 as default, no matter what other Java versions are installed, make sure that you install the oracle-java8-set-default package

@vwal
Copy link

vwal commented Feb 3, 2017

@JJ You should have python-software-properties installed (it includes python-apt). From Salt docs:

On Ubuntu systems, the python-software-properties package should be installed for better support of PPA repositories.

@Bartuz
Copy link

Bartuz commented Feb 16, 2017

INFO    ] Completed state [git] at time 23:40:59.970228 duration_in_ms=322.06
local:
----------
          ID: git-deps
    Function: pkg.installed
        Name: git
      Result: False
     Comment: Failed to get virtual package information (E:Type 'oracle-ppa' is not known on line 16 in source list /etc/apt/sources.list)
     Started: 23:40:59.648168
    Duration: 322.06 ms
     Changes:

Summary for local
------------
Succeeded: 0
Failed:    1
------------
Total states run:     1
Total run time: 322.060 ms
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!

salt-call state.highstate --retcode-passthrough  --log-level=info --force-color

Stdout from the command:

local:
----------
          ID: git-deps
    Function: pkg.installed
        Name: git
      Result: False
     Comment: Failed to get virtual package information (E:Type 'oracle-ppa' is not known on line 16 in source list /etc/apt/sources.list)
     Started: 23:40:59.648168
    Duration: 322.06 ms
     Changes:

Summary for local

@cr0ss
Copy link

cr0ss commented Jun 1, 2017

In my case keyserver has been unavailable so I've used - keyserver: hkp://keyserver.ubuntu.com:80 which seems to got a problem fixed.

@felixhummel
Copy link

You might want to consider using prereq, so the debconf selects only run when pkg.installed is triggered, e.g.

https://github.com/felixhummel/saltstates/blob/master/java/oracle.sls

Thanks for sharing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment