Skip to content

Commit

Permalink
Update cache on java installation
Browse files Browse the repository at this point in the history
  • Loading branch information
Alberto Garcia Fernandez committed Nov 18, 2016
1 parent 6b730a5 commit af16acb
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[flake8]
ignore = E501
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
tests/playbook.retry
tests/.cache
tests/__pycache__
.molecule
.vagrant
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,9 @@ molecule test
```

There is a pre_task with python2 to satisfy ubuntu vbox image dependencies

## Omit linter

[ANSIBLE0010] Line 28 tasks/main.yml Omit linter as we usually want jdk on latest version within propper version
[ANSIBLE0010] Line 35 tasks/main.yml Omit linter as we usually want this package on latest versions aswell as previous one
[ANSIBLE0012] Line 5 tests/playbook.yml Omit linter as we dont care about syntax on this pre_tasks. Its just to allow testing on ubuntu
2 changes: 1 addition & 1 deletion meta/main.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
---
galaxy_info:
description: Prometheus node_exporter role
description: Java role, install java versions and set systems default
8 changes: 6 additions & 2 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@
- name: Debian repo key
apt_repository:
repo: "{{ java_repo }}"
update_cache: yes
when: ansible_distribution in [ 'Debian' ]

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

- name: Autoaccept license for Java
Expand All @@ -30,13 +28,19 @@
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:
Expand Down
5 changes: 4 additions & 1 deletion tests/playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
hosts: all
gather_facts: no
pre_tasks:
- raw: sudo apt-get -y install python-simplejson
- name: Install python2 on Ubuntu
raw: sudo apt-get -y install python-simplejson
changed_when: false
tags: skip_ansible_lint

- hosts: all
roles:
Expand Down
6 changes: 6 additions & 0 deletions tests/test_ansible.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
import pytest


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


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


@pytest.fixture()
def AnsibleDistribution(Ansible):
return Ansible("setup")["ansible_facts"]["ansible_distribution"]


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")
Expand All @@ -22,10 +26,12 @@ def test_java_resources(File, AnsibleDefaults, AnsibleDistribution):
else:
raise ValueError("Unsupported distribution: " + AnsibleDistribution)


def test_java_package(Package, AnsibleVars):
for version in AnsibleVars["java_version"]:
assert Package("oracle-java" + version + "-installer").is_installed


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
Expand Down

0 comments on commit af16acb

Please sign in to comment.