Skip to content

Commit

Permalink
Merge pull request #4 from idealista/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
jmonterrubio authored Apr 20, 2017
2 parents dad0b3c + c234676 commit e806c93
Show file tree
Hide file tree
Showing 12 changed files with 197 additions and 80 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ tests/.cache
tests/__pycache__
.molecule
.vagrant
.cache
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
# Change Log
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/) and [Keep a changelog](https://github.com/olivierlacan/keep-a-changelog).

## [Unreleased]
## [Unreleased](https://github.com/idealista/java-role/tree/develop)

## [1.0.0]
## [1.1.0](https://github.com/idealista/java-role/tree/1.1.0)
### Added
- *Enable openjdk* @jmonterrubio

## [1.0.0](https://github.com/idealista/java-role/tree/1.0.0)
### Added
- *First commit* @agarcia
10 changes: 6 additions & 4 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
---
java_repo: 'deb http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main'
java_ppa: 'webupd8team/java'
java_version: '8'
java_set_version: '8'
## GLOBAL
java_version: 8
java_set_version: 8

# IMPLEMENTATION
java_implementation: oracle # [oracle, openjdk]
15 changes: 13 additions & 2 deletions molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ ansible:
# configuration options for the internal call to vagrant
vagrant:
# molecule's --platform option will look for these names
raw_config_args:
- "landrush.enabled = true"
- "landrush.tld = 'vm'"
- "landrush.guest_redirect_dns = false"
platforms:
- name: Debian
box: debian/jessie64
Expand All @@ -43,9 +47,16 @@ vagrant:
cpus: 1

instances:
- name: vagrant
- name: oracle
ansible_groups:
- group01
- oracle
interfaces:
- network_name: private_network
type: dhcp
auto_config: true
- name: openjdk
ansible_groups:
- openjdk
interfaces:
- network_name: private_network
type: dhcp
Expand Down
35 changes: 35 additions & 0 deletions tasks/install_openjdk.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---

- name: JAVA | Debian repo key
apt_repository:
repo: "{{ java_repo_openjdk }}"
when: ansible_distribution in [ 'Debian' ]

- name: JAVA | Installing dependencies
apt:
pkg: "{{ item }}"
update_cache: yes
state: present
default_release: jessie-backports
with_items: "{{ required_libs_openjdk }}"

- name: JAVA | Install Java
apt:
name: "openjdk-{{ item }}-jdk"
state: present
update_cache: yes
default_release: jessie-backports
with_items: "{{ java_version }}"

- name: JAVA | Update Env
alternatives:
name: java
path: "/usr/lib/jvm/java-{{ java_set_version }}-openjdk-amd64/jre/bin/java"
#command: update-java-alternatives --set java-1.{{ java_set_version }}.0-openjdk-amd64

- name: JAVA | Ensure Defaults on etc/alternatives systems
file:
src: /usr/lib/jvm/java-{{ java_set_version }}-openjdk-amd64
dest: /usr/lib/jvm/default-java
force: yes
state: link
50 changes: 50 additions & 0 deletions tasks/install_oracle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
- name: Debian repo
apt_key:
keyserver: hkp://keyserver.ubuntu.com:80
id: EEA14886
when: ansible_distribution in [ 'Debian' ]

- name: Debian repo key
apt_repository:
repo: "{{ java_repo_oracle }}"
when: ansible_distribution in [ 'Debian' ]

- name: Add Java ppa to Ubuntu
apt_repository:
repo: ppa:{{ java_ppa_oracle }}
when: ansible_distribution in [ 'Ubuntu' ]

- name: Autoaccept license for Java
debconf:
name: oracle-java{{ item }}-installer
question: shared/accepted-oracle-license-v1-1
value: 'true'
vtype: select
with_items: "{{ java_version }}"

- name: Install Java
apt:
pkg: oracle-java{{ item }}-installer
state: present
install_recommends: yes
update_cache: yes
cache_valid_time: 3600
with_items: "{{ java_version }}"
tags: skip_ansible_lint

- name: Set Java Env
apt:
pkg: oracle-java{{ java_set_version }}-set-default
state: present
install_recommends: yes
update_cache: yes
cache_valid_time: 3600
tags: skip_ansible_lint

- name: Ensure Defaults on etc/alternatives systems
file:
src: /usr/lib/jvm/java-{{ java_set_version }}-oracle
dest: /usr/lib/jvm/default-java
force: yes
state: link
59 changes: 11 additions & 48 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,50 +1,13 @@
---
- name: Debian repo
apt_key:
keyserver: hkp://keyserver.ubuntu.com:80
id: EEA14886
when: ansible_distribution in [ 'Debian' ]

- name: Debian repo key
apt_repository:
repo: "{{ java_repo }}"
when: ansible_distribution in [ 'Debian' ]

- name: Add Java ppa to Ubuntu
apt_repository:
repo: ppa:{{ java_ppa }}
when: ansible_distribution in [ 'Ubuntu' ]

- name: Autoaccept license for Java
debconf:
name: oracle-java{{ item }}-installer
question: shared/accepted-oracle-license-v1-1
value: 'true'
vtype: select
with_items: "{{ java_version }}"

- name: Install Java
apt:
pkg: oracle-java{{ item }}-installer
state: latest
install_recommends: yes
update_cache: yes
cache_valid_time: 3600
with_items: "{{ java_version }}"
tags: skip_ansible_lint

- name: Set Java Env
apt:
pkg: oracle-java{{ java_set_version }}-set-default
state: latest
install_recommends: yes
update_cache: yes
cache_valid_time: 3600
tags: skip_ansible_lint

- name: Ensure Defaults on etc/alternatives systems
file:
src: /usr/lib/jvm/java-{{ java_set_version }}-oracle
dest: /usr/lib/jvm/default-java
force: yes
state: link
- name: JAVA | Install Oracle Implementation
include: install_oracle.yml
when: java_implementation == 'oracle'
tags:
- install

- name: JAVA | Install OpenJDK Implementation
include: install_openjdk.yml
when: java_implementation == 'openjdk'
tags:
- install
7 changes: 7 additions & 0 deletions tests/group_vars/openjdk.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---

java_version: [7,8]

java_set_version: 7

java_implementation: openjdk
6 changes: 6 additions & 0 deletions tests/group_vars/oracle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---

java_version: [6, 7, 8]
java_set_version: 7

java_implementation: oracle
8 changes: 6 additions & 2 deletions tests/playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
changed_when: false
tags: skip_ansible_lint

- hosts: all
- hosts: oracle
roles:
- role: java-role
- java-role

- hosts: openjdk
roles:
- java-role
67 changes: 45 additions & 22 deletions tests/test_ansible.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,61 @@


@pytest.fixture()
def AnsibleDefaults(Ansible):
return Ansible("include_vars", "defaults/main.yml")["ansible_facts"]
def AnsibleDefaultVars(Ansible):
return Ansible("include_vars", "vars/main.yml")["ansible_facts"]


@pytest.fixture()
def AnsibleVars(Ansible):
return Ansible("include_vars", "tests/group_vars/group01.yml")["ansible_facts"]
def AnsibleDefaults(Ansible):
return Ansible("include_vars", "defaults/main.yml")["ansible_facts"]


@pytest.fixture()
def AnsibleDistribution(Ansible):
return Ansible("setup")["ansible_facts"]["ansible_distribution"]
def AnsibleVarsOracle(Ansible):
return Ansible("include_vars", "tests/group_vars/oracle.yml")["ansible_facts"]


def test_java_resources(File, AnsibleDefaults, AnsibleDistribution):
if AnsibleDistribution == "Debian":
java_resources = File("/etc/apt/sources.list.d/ppa_launchpad_net_webupd8team_java_ubuntu.list")
assert java_resources.contains(AnsibleDefaults["java_repo"])
elif AnsibleDistribution == "Ubuntu":
java_resources = File("/etc/apt/sources.list.d/ppa_webupd8team_java_xenial.list")
assert java_resources.contains("deb http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main")
else:
raise ValueError("Unsupported distribution: " + AnsibleDistribution)
@pytest.fixture()
def AnsibleVarsOpenjdk(Ansible):
return Ansible("include_vars", "tests/group_vars/openjdk.yml")["ansible_facts"]


def test_java_package(Package, AnsibleVars):
for version in AnsibleVars["java_version"]:
assert Package("oracle-java" + version + "-installer").is_installed
@pytest.fixture()
def AnsibleDistribution(Ansible):
return Ansible("setup")["ansible_facts"]["ansible_distribution"]


def test_java_default(File, Package, Command, AnsibleVars):
assert Package("oracle-java" + AnsibleVars["java_set_version"] + "-set-default").is_installed
assert AnsibleVars["java_set_version"] in Command("java -version").stderr
@pytest.fixture()
def Hostname(TestinfraBackend):
return TestinfraBackend.get_hostname()


def test_java_resources(File, AnsibleDefaultVars, AnsibleDistribution, Hostname):
if "oracle" in Hostname:
if AnsibleDistribution == "Debian":
java_resources = File("/etc/apt/sources.list.d/ppa_launchpad_net_webupd8team_java_ubuntu.list")
assert java_resources.contains(AnsibleDefaultVars["java_repo_oracle"])
elif AnsibleDistribution == "Ubuntu":
java_resources = File("/etc/apt/sources.list.d/ppa_webupd8team_java_xenial.list")
assert java_resources.contains("deb http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main")
else:
raise ValueError("Unsupported distribution: " + AnsibleDistribution)


def test_java_package(Package, AnsibleVarsOracle, AnsibleVarsOpenjdk, Hostname):
if "oracle" in Hostname:
for version in AnsibleVarsOracle["java_version"]:
assert Package("oracle-java" + str(version) + "-installer").is_installed
if "openjdk" in Hostname:
for version in AnsibleVarsOpenjdk["java_version"]:
assert Package("openjdk-" + str(version) + "-jdk").is_installed


def test_java_default(File, Package, Command, AnsibleVarsOracle, AnsibleVarsOpenjdk, Hostname):
if "oracle" in Hostname:
assert Package("oracle-java" + str(AnsibleVarsOracle["java_set_version"]) + "-set-default").is_installed
assert File("/usr/lib/jvm/default-java").linked_to == "/usr/lib/jvm/java-" + str((AnsibleVarsOracle["java_set_version"])) + "-oracle"
assert str(AnsibleVarsOracle["java_set_version"]) in Command("java -version").stderr
if "openjdk" in Hostname:
assert str(AnsibleVarsOpenjdk["java_set_version"]) in Command("java -version").stderr
assert File("/usr/lib/jvm/default-java").is_symlink
assert File("/usr/lib/jvm/default-java").linked_to == "/usr/lib/jvm/java-" + (AnsibleVars["java_set_version"]) + "-oracle"
10 changes: 10 additions & 0 deletions vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---

required_libs_oracle: []
java_repo_oracle: "deb http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main"
java_ppa_oracle: "webupd8team/java"

required_libs_openjdk:
- ca-certificates-java
- openjdk-8-jre-headless
java_repo_openjdk: "deb http://http.debian.net/debian jessie-backports main"

0 comments on commit e806c93

Please sign in to comment.