Skip to content

Commit f86d4a6

Browse files
committed
Merge pull request #21 from ansiblebit/develop
v4.9.8
2 parents 8e5555d + 8a92816 commit f86d4a6

File tree

10 files changed

+200
-57
lines changed

10 files changed

+200
-57
lines changed

meta/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ galaxy_info:
88
description: Role to install Oracle Java.
99
company: ansiblebit.org
1010
license: BSD
11-
min_ansible_version: 1.9.3
11+
min_ansible_version: 1.9.4
1212
platforms:
1313
- name: CentOS
1414
versions:

tasks/check_environment.yml

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,20 @@
1616
# oracle_java_installed.rc == 0 : installed
1717
# oracle_java_installed.rc == 1 : not installed
1818

19-
- name: echo oracle_java_task_installed
20-
debug:
21-
msg="oracle_java_task_installed={{ oracle_java_task_installed }}"
19+
- debug:
20+
var=oracle_java_task_installed
2221
when: oracle_java_task_installed is defined
2322
tags:
2423
- debug
2524

2625
- name: set fact oracle_java_installed
2726
set_fact:
2827
oracle_java_installed={{ oracle_java_task_installed.rc == 0 }}
28+
when: oracle_java_task_installed is defined and oracle_java_task_installed.rc is defined
2929
changed_when: False
3030

31-
- name: echo oracle_java_installed
32-
debug:
33-
msg="oracle_java_installed={{ oracle_java_installed }}"
31+
- debug:
32+
var=oracle_java_installed
3433
when: oracle_java_installed is defined
3534
tags:
3635
- debug
@@ -40,33 +39,30 @@
4039

4140
- name: if Java is installed, check version
4241
shell: java -version 2>&1 | head -n 1 | awk '{ print $3 }' | awk -F '"' '{ print $2 }'
43-
when: oracle_java_installed
42+
when: oracle_java_installed is defined
4443
register: oracle_java_task_version
4544
changed_when: False
4645

47-
- name: echo oracle_java_task_version
48-
debug:
49-
msg="oracle_java_task_version={{ oracle_java_task_version }}"
46+
- debug:
47+
var=oracle_java_task_version
5048
when: oracle_java_task_version is defined
5149
tags:
5250
- debug
5351

5452
- name: set fact oracle_java_installed_version
5553
set_fact:
5654
oracle_java_version_installed={{ oracle_java_task_version.stdout }}
57-
when: oracle_java_installed
55+
when: oracle_java_task_version is defined and oracle_java_task_version.stdout is defined
5856
changed_when: False
5957

60-
- name: echo oracle_java_version_installed
61-
debug:
62-
msg="oracle_java_version_installed={{ oracle_java_version_installed }}"
58+
- debug:
59+
var=oracle_java_version_installed
6360
when: oracle_java_version_installed is defined
6461
tags:
6562
- debug
6663

67-
- name: echo oracle_java_version_string
68-
debug:
69-
msg="oracle_java_version_string={{ oracle_java_version_string }}"
64+
- debug:
65+
var=oracle_java_version_string
7066
when: oracle_java_version_string is defined
7167
tags:
7268
- debug

tasks/redhat/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@
2828
name="{{ item.exe }}"
2929
link="/usr/bin/{{ item.exe }}"
3030
path="{{ item.path }}/{{ item.exe }}"
31-
when: oracle_java_set_as_default
3231
with_items:
3332
- { path: "{{ oracle_java_home }}/jre/bin", exe: 'java' }
3433
- { path: "{{ oracle_java_home }}/jre/bin", exe: 'keytool' }
3534
- { path: "{{ oracle_java_home }}/bin", exe: 'javac' }
3635
- { path: "{{ oracle_java_home }}/bin", exe: 'javadoc' }
3736
sudo: yes
38-
when: oracle_java_task_rpm_download|changed or (oracle_java_installed and oracle_java_version_installed != oracle_java_version_string)
37+
when: (oracle_java_set_as_default and oracle_java_task_rpm_download|changed) or
38+
(oracle_java_set_as_default and oracle_java_installed and oracle_java_version_installed != oracle_java_version_string)
3939
register: oracle_java_task_set_default
4040

4141
- name: in case there were changes, check host environment again

tests/plugins/callback/idempotence.py

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,49 @@
1+
# -*- coding: utf-8 -*-
2+
3+
from __future__ import (absolute_import, print_function)
4+
15
import sys
26
import os
37

4-
VAR_IDEMPOTENCE = u'idempotence'
8+
from ansible import constants as C
9+
from ansible.constants import mk_boolean
10+
11+
try:
12+
from ansible.plugins.callback import CallbackBase
13+
parent = CallbackBase
14+
except ImportError:
15+
parent = object
16+
17+
18+
VAR_IDEMPOTENCE = u'IDEMPOTENCE'
519

620

7-
class CallbackModule(object):
21+
class CallbackModule(parent):
822
"""
9-
This callback module performs the idempotence test whenever the 'idempotence' variable is set to True.
23+
This callback module performs the idempotency test whenever the 'idempotency' variable is set to True.
1024
"""
25+
CALLBACK_VERSION = 2.0
26+
CALLBACK_NAME = 'idempotency'
1127

1228
def __init__(self):
13-
pass
29+
self.playbook = None
30+
self.enabled = mk_boolean(os.getenv(VAR_IDEMPOTENCE, 'no'))
1431

15-
def playbook_on_stats(self, stats):
32+
super(CallbackModule, self).__init__()
1633

17-
if (u'%s' % VAR_IDEMPOTENCE) in self.playbook.extra_vars.keys() and self.playbook.extra_vars[VAR_IDEMPOTENCE]:
34+
def playbook_on_stats(self, stats):
1835

36+
if self.enabled:
1937
if len(stats.dark) > 0:
20-
print ('idempotence test failed! unreachable=%s > 0') % stats.dark
38+
self._display.warning('idempotency test failed: unreachable=%s > 0' % stats.dark)
2139
sys.exit(os.EX_SOFTWARE)
22-
2340
if len(stats.changed) > 0:
24-
print ('idempotence test failed! changed=%s > 0') % stats.changed
41+
self._display.warning('idempotency test failed: changed=%s > 0' % stats.changed)
2542
sys.exit(os.EX_SOFTWARE)
26-
2743
if len(stats.failures) > 0:
28-
print ('idempotence test failed! failures=%s > 0') % stats.failures
44+
self._display.warning('idempotency test failed: failures=%s > 0' % stats.failures)
2945
sys.exit(os.EX_SOFTWARE)
46+
47+
def v2_playbook_on_stats(self, stats):
48+
"""Verify that playbook ran without any changes or failures."""
49+
self.playbook_on_stats(stats)

tests/tasks/main.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,12 @@
3333
fail:
3434
msg="java -version output was {{ result_java_version.stdout }} instead of {{ expected_java_version }}"
3535
when: result_java_version.stdout != expected_java_version
36+
37+
- name: ensure keytool and javadoc are present
38+
shell: "test -h /usr/bin/{{ item }}"
39+
changed_when: no
40+
with_items:
41+
- keytool
42+
- java
43+
- javadoc
44+

tests/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
vars:
99
test_java_version: 8
10-
test_java_version_update: 72
10+
test_java_version_update: 74
1111
test_java_version_build: 15
1212

1313
roles:

tests/test_checkmode.sh

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
#!/usr/bin/env bash
2+
# #################
3+
#
4+
# Bash script to run check mode tests.
5+
#
6+
# version: 1.5
7+
#
8+
# usage:
9+
#
10+
# test_checkmode [options]
11+
#
12+
# options:
13+
#
14+
# --box The name of the Vagrant box or host name
15+
# --env The name of the test environment
16+
# --inventory The Ansible inventory in the form of a file or string "host,"
17+
# --playbook The path to the Ansible test playbook
18+
#
19+
# example:
20+
#
21+
# # on localhost
22+
# bash test_checkmode.sh
23+
#
24+
# # on a Vagrant box
25+
# bash test_checkmode.sh \
26+
# --box precise64.vagrant.dev \
27+
# --inventory .vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory
28+
#
29+
#
30+
# changelog:
31+
#
32+
# v1.5 : 8 Mar 2016
33+
# - pass vagrant_box variable to playbook
34+
# - default inventory changed from localhost to match what Vagrant provisioner generates
35+
# v1.4 : 10 Jul 2015
36+
# - added extra variables to force running idempotence tests on vagrant
37+
# v1.2
38+
# - added env option
39+
#
40+
# author(s):
41+
# - Pedro Salgado <[email protected]>
42+
#
43+
# #################
44+
45+
46+
# GREEN : SGR code to set text color (foreground) to green.
47+
GREEN='\033[0;32m'
48+
# RED : SGR code to set text color (foreground) to red.
49+
RED='\033[0;31m'
50+
# SGR code to set text color (foreground) to no color.
51+
NC='\033[0m'
52+
# The idempotence pass criteria.
53+
PASS_CRITERIA="changed=0.* unreachable=0.* failed=0"
54+
55+
# the name of the virtualenv
56+
VIRTUALENV_NAME=$(which python | awk -F / 'NF && NF-2 { print ( $(NF-2) ) }')
57+
58+
59+
while [[ $# > 1 ]]
60+
do
61+
key="$1"
62+
63+
case $key in
64+
65+
--box)
66+
# the name of the Vagrant box or host name
67+
BOX="$2"
68+
shift;;
69+
70+
--env)
71+
# the test environment
72+
ENV="$2"
73+
shift;;
74+
75+
--inventory)
76+
# the Ansible inventory in the form of a file or string "host,"
77+
INVENTORY="$2"
78+
shift;;
79+
80+
--playbook)
81+
# the path to the Ansible test playbook
82+
PLAYBOOK="$2"
83+
shift;;
84+
85+
*)
86+
# unknown option
87+
;;
88+
89+
esac
90+
shift
91+
done
92+
93+
# the name of the Vagrant box or host name
94+
BOX=${BOX:-localhost}
95+
# the Ansible inventory
96+
INVENTORY=${INVENTORY:-'.vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory'}
97+
# the path to the Ansible test playbook
98+
PLAYBOOK=${PLAYBOOK:-test.yml}
99+
# the logfile to hold the output of the playbook run
100+
LOGFILE="log/${BOX}_checkmode_${VIRTUALENV_NAME}.log"
101+
102+
EXTRA_ARGS=''
103+
if [ $BOX == "localhost" ]; then
104+
INVENTORY='localhost,'
105+
EXTRA_ARGS="--connection=local -e env=${ENV} -e vagrant_box=localhost --skip-tags=test"
106+
else
107+
EXTRA_ARGS="--user vagrant -e env=vagrant -e vagrant_box=${BOX} --skip-tags=test"
108+
fi
109+
110+
echo "[INFO] ${BOX} ${VIRTUALENV_NAME} running checkmode test..."
111+
ansible-playbook -vvvv --check --diff -i ${INVENTORY} --limit ${BOX}, ${EXTRA_ARGS} ${PLAYBOOK} 2>&1 | \
112+
tee ${LOGFILE} | \
113+
grep "${BOX}" | grep -q "${PASS_CRITERIA}" && \
114+
echo -ne "[TEST] ${BOX} ${VIRTUALENV_NAME} checkmode : ${GREEN}PASS${NC}\n" || ( \
115+
cat ${LOGFILE} &&
116+
echo -ne "[TEST] ${BOX} ${VIRTUALENV_NAME} checkmode : ${RED}FAILED${NC} ${PASS_CRITERIA}\n" && \
117+
exit 1)

tests/test_idempotence.sh

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44
# Bash script to run idempotence tests.
55
#
6-
# version: 1.4
6+
# version: 1.5
77
#
88
# usage:
99
#
@@ -23,12 +23,15 @@
2323
#
2424
# # on a Vagrant box
2525
# bash test_idempotence.sh \
26-
# --box precise64.vagrant.dev
26+
# --box precise64.vagrant.dev \
2727
# --inventory .vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory
2828
#
2929
#
3030
# changelog:
3131
#
32+
# v1.5 : 8 Mar 2016
33+
# - pass vagrant_box variable to playbook
34+
# - default inventory changed from localhost to match what Vagrant provisioner generates
3235
# v1.4 : 10 Jul 2015
3336
# - added extra variables to force running idempotence tests on vagrant
3437
# v1.2
@@ -47,7 +50,7 @@ RED='\033[0;31m'
4750
# SGR code to set text color (foreground) to no color.
4851
NC='\033[0m'
4952
# The idempotence pass criteria.
50-
PASS_CRITERIA="changed=0.*unreachable=0.*failed=0"
53+
PASS_CRITERIA="changed=0.* unreachable=0.* failed=0"
5154

5255
# the name of the virtualenv
5356
VIRTUALENV_NAME=$(which python | awk -F / 'NF && NF-2 { print ( $(NF-2) ) }')
@@ -89,22 +92,27 @@ done
8992

9093
# the name of the Vagrant box or host name
9194
BOX=${BOX:-localhost}
92-
# the Ansible inventory in the form of a file or string "host,"
93-
INVENTORY=${INVENTORY:-'localhost,'}
95+
# the Ansible inventory
96+
INVENTORY=${INVENTORY:-'.vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory'}
9497
# the path to the Ansible test playbook
9598
PLAYBOOK=${PLAYBOOK:-test.yml}
9699
# the logfile to hold the output of the playbook run
97-
LOGFILE="log/${BOX}_${VIRTUALENV_NAME}.log"
100+
LOGFILE="log/${BOX}_idempotence_${VIRTUALENV_NAME}.log"
98101

99102
EXTRA_ARGS=''
100103
if [ $BOX == "localhost" ]; then
101-
EXTRA_ARGS="--connection=local --extra-vars idempotence=yes --extra-vars env=${ENV}"
104+
INVENTORY='localhost,'
105+
EXTRA_ARGS="--connection=local -e env=${ENV} -e vagrant_box=localhost"
102106
else
103-
EXTRA_ARGS="--u vagrant --extra-vars idempotence=yes --extra-vars env=vagrant"
107+
EXTRA_ARGS="--user vagrant -e env=vagrant -e vagrant_box=${BOX}"
104108
fi
105109

106110
echo "[INFO] ${BOX} ${VIRTUALENV_NAME} running idempotence test..."
107-
ansible-playbook -i ${INVENTORY} --limit ${BOX}, ${EXTRA_ARGS} ${PLAYBOOK} 2>&1 | tee ${LOGFILE} | \
111+
IDEMPOTENCE='yes' \
112+
ansible-playbook -vvvv -i ${INVENTORY} --limit ${BOX}, ${EXTRA_ARGS} ${PLAYBOOK} 2>&1 | \
113+
tee ${LOGFILE} | \
108114
grep "${BOX}" | grep -q "${PASS_CRITERIA}" && \
109-
echo -ne "[TEST] ${BOX} ${VIRTUALENV_NAME} idempotence : ${GREEN}PASS${NC}\n" || \
110-
(echo -ne "[TEST] ${BOX} ${VIRTUALENV_NAME} idempotence : ${RED}FAILED${NC} ${PASS_CRITERIA}\n" && cat ${LOGFILE} && exit 1)
115+
echo -ne "[TEST] ${BOX} ${VIRTUALENV_NAME} idempotence : ${GREEN}PASS${NC}\n" || ( \
116+
cat ${LOGFILE} &&
117+
echo -ne "[TEST] ${BOX} ${VIRTUALENV_NAME} idempotence : ${RED}FAILED${NC} ${PASS_CRITERIA}\n" && \
118+
exit 1)

tests/vagrant.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ do
6363
fi
6464

6565
bash ${DIR}/test_idempotence.sh --box ${VAGRANT_BOX} --inventory $INVENTORY
66+
bash ${DIR}/test_checkmode.sh --box ${VAGRANT_BOX} --inventory $INVENTORY
6667

6768
echo "[INFO] destroy ${VAGRANT_BOX}..."
6869
vagrant destroy -f ${VAGRANT_BOX}

0 commit comments

Comments
 (0)