Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
smola committed Jul 30, 2014
0 parents commit a2bb70f
Show file tree
Hide file tree
Showing 17 changed files with 259 additions and 0 deletions.
36 changes: 36 additions & 0 deletions .travis.yml
@@ -0,0 +1,36 @@
---
language: python
python: "2.7"

env:
- SITE=test.yml

before_install:
- sudo apt-get update -qq
- sudo apt-get install -y curl

install:
# Install Ansible.
- pip install ansible==1.5.0

script:
- "cd tests"

# Check the role/playbook's syntax.
- "ansible-playbook -i inventory $SITE --syntax-check"

# Run the role/playbook with ansible-playbook.
- "ansible-playbook -i inventory $SITE --connection=local --sudo"

# Run the role/playbook again, checking to make sure it's idempotent.
- >
ansible-playbook -i inventory $SITE --connection=local --sudo
| grep -q 'changed=0.*failed=0'
&& (echo 'Idempotence test: pass' && exit 0)
|| (echo 'Idempotence test: fail' && exit 1)
# Make sure Java is installed.
- >
which java
&& (echo 'Java is installed' && exit 0)
|| (echo 'Java is not installed' && exit 1)
19 changes: 19 additions & 0 deletions LICENSE
@@ -0,0 +1,19 @@
Copyright (c) 2014 Santiago M. Mola <santi@mola.io>

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
77 changes: 77 additions & 0 deletions README.md
@@ -0,0 +1,77 @@
Ansible Java Role
=================

[![Build Status](https://travis-ci.org/smola/ansible-java-role.svg?branch=master)](https://travis-ci.org/smola/ansible-java-role)

Manages installation of Java JREs and JDKs. It supports both OpenJDK and Oracle
JRE and JDK 6, 7 and 8. All of them are installed using the package manager.

Requirements
------------

None.

Role Variables
--------------

The `java_packages` variable must be set to a list of the desired Java packages. For example:

```yaml
java_packages:
- openjdk-6-jdk
- oracle-java7-installer
```

# Debian / Ubuntu

Valid packages for Debian and Ubuntu are:

- openjdk-6-jre
- openjdk-6-jre-headless
- openjdk-6-jdk
- openjdk-7-jre
- openjdk-7-jre-headless
- openjdk-7-jdk
- oracle-java6-installer
- oracle-java7-installer
- oracle-java8-installer

32bit Java may be installed on x86 platforms appending `:i386` to the package name.

You can ensure that Oracle JDK is set as the default JDK by adding `oracle-java6-set-default`, `oracle-java7-set-default` or `oracle-java6-set-default` to the `java\_packages` list.

# Fedora

Valid packages for Fedora are:

- java-1.7.0-openjdk
- java-1.8.0-openjdk

# Others

Got this role working with a different distro? Please, [report it on GitHub](http://github.com/smola/ansible-java-role/issues) or drop me a line at santi@mola.io.

Dependencies
------------

None.

Example Playbook
-------------------------

- hosts: servers
roles:
- { role: smola.java }

License
-------

Copyright (c) Santiago M. Mola <santi@mola.io>

ansible-java-role is released under the terms of the MIT License.


Acknowledgements
----------------

Thanks to Jeff Geerling ([@geerlingguy](https://github.com/geerlingguy)) from whom I have borrowed some ideas from his [ansible-java-role](https://github.com/geerlingguy/ansible-role-java) and [Testing Ansible Roles with Travis CI on GitHub](https://servercheck.in/blog/testing-ansible-roles-travis-ci-github).
3 changes: 3 additions & 0 deletions defaults/main.yml
@@ -0,0 +1,3 @@
---
java_packages: []
java_cleanup: True
23 changes: 23 additions & 0 deletions meta/main.yml
@@ -0,0 +1,23 @@
---
galaxy_info:
author: Santiago M. Mola
description: OpenJDK / Oracle JDK 6, 7 and 8.
license: MIT
min_ansible_version: 1.5
platforms:
- name: Ubuntu
versions:
- all
- name: Debian
versions:
- all
- name: EL
versions:
- all
- name: Fedora
versions:
- all
categories:
- development
- system
dependencies: []
29 changes: 29 additions & 0 deletions tasks/Debian.yml
@@ -0,0 +1,29 @@
---

- include_vars: Ubuntu.yml

- name: Install python-apt
apt: pkg=python-apt

- include: webupd8_for_debian.yml
when: "ansible_distribution != 'Ubuntu'"

- include: webupd8_for_ubuntu.yml
when: ansible_distribution == 'Ubuntu'

- name: Accept Oracle License
debconf: name={{ item }} question='shared/accepted-oracle-license-v1-1' value='true' vtype='select'
with_items:
- oracle-java6-installer
- oracle-java7-installer
- oracle-java8-installer
when: java_needs_oracle

- name: Install Java packages
apt: pkg={{ item }} state=latest
with_items: java_packages

- name: Remove unwanted Java packages
apt: pkg={{ item }} state=absent
with_items: java_packages_to_remove
when: java_cleanup
9 changes: 9 additions & 0 deletions tasks/RedHat.yml
@@ -0,0 +1,9 @@
---

- name: Install Java packages
yum: name={{ item }} state=latest
with_items: java_packages
when: ansible_os_family == 'RedHat'



3 changes: 3 additions & 0 deletions tasks/main.yml
@@ -0,0 +1,3 @@
---
- include: Debian.yml
when: ansible_os_family == 'Debian'
2 changes: 2 additions & 0 deletions tasks/webupd8.yml
@@ -0,0 +1,2 @@
---

12 changes: 12 additions & 0 deletions tasks/webupd8_for_debian.yml
@@ -0,0 +1,12 @@
---

- name: Install WebUpd8 apt key
apt_key: id=EEA14886 state=present

- name: Install WebUpd8 Team Java PPA (for Oracle Java)
apt_repository: repo='deb http://ppa.launchpad.net/webupd8team/java/ubuntu precise main' state=present
when: java_needs_oracle

- name: Remove WebUpd8 Team Java PPA (for Oracle Java)
apt_repository: repo='deb http://ppa.launchpad.net/webupd8team/java/ubuntu precise main' state=present
when: java_cleanup and not java_needs_oracle
8 changes: 8 additions & 0 deletions tasks/webupd8_for_ubuntu.yml
@@ -0,0 +1,8 @@
---
- name: Install WebUpd8 Team Java PPA (for Oracle Java)
apt_repository: repo='ppa:webupd8team/java' state=present
when: java_needs_oracle

- name: Remove WebUpd8 Team Java PPA (for Oracle Java)
apt_repository: repo='ppa:webupd8team/java' state=present
when: java_cleanup and not java_needs_oracle
2 changes: 2 additions & 0 deletions tests/ansible.cfg
@@ -0,0 +1,2 @@
[defaults]
roles_path=../../
5 changes: 5 additions & 0 deletions tests/group_vars/test
@@ -0,0 +1,5 @@
---
java_packages:
- oracle-java8-set-default
- oracle-java8-installer
- openjdk-6-jdk
2 changes: 2 additions & 0 deletions tests/inventory
@@ -0,0 +1,2 @@
[test]
localhost
5 changes: 5 additions & 0 deletions tests/test.yml
@@ -0,0 +1,5 @@
---
- hosts: test
remote_user: root
roles:
- ansible-java-role
22 changes: 22 additions & 0 deletions vars/Ubuntu.yml
@@ -0,0 +1,22 @@
---
# JREs are not included in the list.
# Otherwise, JDK would be incorrectly
# cleaned up.
java_packages_full:
- openjdk-6-jdk
- openjdk-6-jdk:i386
#- openjdk-6-jre
#- openjdk-6-jre:i386
#- openjdk-6-jre-headless
#- openjdk-6-jre-headless:i386
#- openjdk-6-jre-zero
#- openjdk-6-jre-zero:i386
- openjdk-7-jdk
- openjdk-7-jdk:i386
#- openjdk-7-jre
#- openjdk-7-jre:i386
#- openjdk-7-jre-headless
#- openjdk-7-jre-headless:i386
#- openjdk-7-jre-zero
#- openjdk-7-jre-zero:i386
java_packages_to_remove: "{{ java_packages_full | difference(java_packages) }}"
2 changes: 2 additions & 0 deletions vars/main.yml
@@ -0,0 +1,2 @@
---
java_needs_oracle: "{{ java_packages | join | search('oracle') }}"

0 comments on commit a2bb70f

Please sign in to comment.