Skip to content

Commit

Permalink
- v3.7.0 : 10 Jul 2015
Browse files Browse the repository at this point in the history
    - don't update the apt repositories cache when you're just adding new repos since it will get updated in the end
    - minor version number will now match primogen major version number
    - merge with ansiblebit.primogen v7
        - upgrade tests to use ansible v1.9.2 instead of v1.9.1
        - pass ANSIBLE_ASK_SUDO_PASS environment variable to the tox test environment
        - improved idempotence test
    - renamed fact os_supported to launchpad_ppa_webupd8_os_supported
  • Loading branch information
steenzout committed Jul 10, 2015
1 parent 6d1beec commit f85d199
Show file tree
Hide file tree
Showing 11 changed files with 97 additions and 35 deletions.
33 changes: 29 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,30 @@

An [Ansible](http://www.ansible.com) role to setup the [webupd8](http://www.webupd8.org/) launchpad apt repository.

## Tests

| Family | Distribution | Version | Test Status |
|:-:|:-:|:-:|:-:|
| Debian | Debian | Jessie | [![x86](http://img.shields.io/badge/x86-n/a-cccccc.svg?style=flat)](#) [![x86_64](http://img.shields.io/badge/x86_64-n/a-cccccc.svg?style=flat)](#) |
| Debian | Debian | Wheezy | [![x86](http://img.shields.io/badge/x86-n/a-cccccc.svg?style=flat)](#) [![x86_64](http://img.shields.io/badge/x86_64-n/a-cccccc.svg?style=flat)](#) |
| Debian | Ubuntu | Precise | [![x86](http://img.shields.io/badge/x86-n/a-cccccc.svg?style=flat)](#) [![x86_64](http://img.shields.io/badge/x86_64-passed-006400.svg?style=flat)](#) |
| Debian | Ubuntu | Trusty | [![x86](http://img.shields.io/badge/x86-n/a-cccccc.svg?style=flat)](#) [![x86_64](http://img.shields.io/badge/x86_64-n/a-cccccc.svg?style=flat)](#) |
| Debian | Ubuntu | Vivid | [![x86](http://img.shields.io/badge/x86-n/a-cccccc.svg?style=flat)](#) [![x86_64](http://img.shields.io/badge/x86_64-n/a-cccccc.svg?style=flat)](#) |
| RedHat | CentOS | 6.4 | [![x86](http://img.shields.io/badge/x86-n/a-cccccc.svg?style=flat)](#) [![x86_64](http://img.shields.io/badge/x86_64-n/a-cccccc.svg?style=flat)](#) |
| RedHat | CentOS | 6.6 | [![x86](http://img.shields.io/badge/x86-n/a-cccccc.svg?style=flat)](#) [![x86_64](http://img.shields.io/badge/x86_64-n/a-cccccc.svg?style=flat)](#) |
| RedHat | Centos | 7 | [![x86](http://img.shields.io/badge/x86-n/a-cccccc.svg?style=flat)](#) [![x86_64](http://img.shields.io/badge/x86_64-n/a-cccccc.svg?style=flat)](#) |
| RedHat | Fedora | 20 | [![x86](http://img.shields.io/badge/x86-n/a-cccccc.svg?style=flat)](#) [![x86_64](http://img.shields.io/badge/x86_64-n/a-cccccc.svg?style=flat)](#) |
| RedHat | Fedora | 21 | [![x86](http://img.shields.io/badge/x86-n/a-cccccc.svg?style=flat)](#) [![x86_64](http://img.shields.io/badge/x86_64-n/a-cccccc.svg?style=flat)](#) |

## Requirements

- ansible >= 1.8.4

# Facts
| variable | description |
|:-:|:--|
| launchpad_ppa_webupd8_os_supported | fact set by this role to determine if the host OS is supported. |

## Role Variables

| variable | description |
Expand All @@ -36,6 +56,14 @@ is always nice for users too:

## Changelog

- v3.7.0 : 10 Jul 2015
- don't update the apt repositories cache when you're just adding new repos since it will get updated in the end
- minor version number will now match primogen major version number
- merge with ansiblebit.primogen v7
- upgrade tests to use ansible v1.9.2 instead of v1.9.1
- pass ANSIBLE_ASK_SUDO_PASS environment variable to the tox test environment
- improved idempotence test
- renamed fact os_supported to launchpad_ppa_webupd8_os_supported
- v3.0.0 : 7 May 2015
- synchronized major version with primogen for easier reference
- v1.1.2 : 5 May 2015
Expand All @@ -55,6 +83,7 @@ is always nice for users too:

## Links

- [WebUpd8 team : Oracle Java (JDK) 7 / 8 / 9 Installer PPA](https://launchpad.net/~webupd8team/+archive/ubuntu/java)

## License

Expand All @@ -63,7 +92,3 @@ BSD
## Author Information

- [steenzout](http://github.com/steenzout)

## Links

- [WebUpd8 team : Oracle Java (JDK) 7 / 8 / 9 Installer PPA](https://launchpad.net/~webupd8team/+archive/ubuntu/java)
2 changes: 1 addition & 1 deletion tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
- name: check if operating system is suported
fail:
msg: "The operating system ({{ ansible_os_family }}) of the target machine ({{ inventory_hostname }}) is not currently supported."
when: os_supported is not defined
when: launchpad_ppa_webupd8_os_supported is not defined


## generic tasks
Expand Down
8 changes: 4 additions & 4 deletions tasks/os_distribution/debian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

- name: debian is supported
set_fact:
os_supported: yes
launchpad_ppa_webupd8_os_supported: yes

- name: ensure the webupd8 launchpad apt repository key is present
apt_key:
Expand All @@ -15,13 +15,13 @@
- name: ensure the webupd8 launchpad apt repository is present
apt_repository:
repo="deb http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main"
update_cache=yes
update_cache=no
state=present
sudo: yes

- name: ensure the webupd8 launchpad apt repository is present
- name: ensure the webupd8 launchpad source apt repository is present
apt_repository:
repo="deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main"
update_cache=yes
update_cache=no
state=present
sudo: yes
4 changes: 2 additions & 2 deletions tasks/os_distribution/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

- name: ubuntu is supported
set_fact:
os_supported: yes
launchpad_ppa_webupd8_os_supported: yes

- name: ensure the webupd8 launchpad apt repository is present
apt_repository:
repo=ppa:webupd8team/java
update_cache=yes
update_cache=no
state=present
sudo: yes
1 change: 1 addition & 0 deletions tests/Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Vagrant.configure('2') do |config|
host.vm.provision 'ansible' do |ansible|
ansible.playbook = PLAYBOOK
ansible.verbose = 'v'
ansible.skip_tags = 'test'
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions tests/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
# file: primogen/tests/tasks
18 changes: 12 additions & 6 deletions tests/plugins/callback/idempotence.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
import sys
import os

VAR_IDEMPOTENCE = u'idempotence'


class CallbackModule(object):
"""
This callback module tells you how long your plays ran for.
This callback module performs the idempotence test whenever the 'idempotence' variable is set to True.
"""

def __init__(self):
pass

def playbook_on_stats(self, stats):

if u'idempotence' in self.playbook.extra_vars.keys():
if (u'%s' % VAR_IDEMPOTENCE) in self.playbook.extra_vars.keys() and self.playbook.extra_vars[VAR_IDEMPOTENCE]:

if len(stats.dark) > 0:
print ('idempotence test failed! unreachable=%s > 0') % stats.dark
sys.exit(os.EX_SOFTWARE)

if (len(stats.changed) > 0):
print 'idempotence test failed! changed=%s > 0' % stats.changed
if len(stats.changed) > 0:
print ('idempotence test failed! changed=%s > 0') % stats.changed
sys.exit(os.EX_SOFTWARE)

if (len(stats.failures) > 0):
print 'idempotence test failed! failures=%s > 0' % stats.failures
if len(stats.failures) > 0:
print ('idempotence test failed! failures=%s > 0') % stats.failures
sys.exit(os.EX_SOFTWARE)
14 changes: 11 additions & 3 deletions tests/test.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
---
# file: launchpad-ppa-webupd8/tests/vagrant.yml
# file: launchpad-ppa-webupd8/tests/test.yml

- name: tests play
- name: provisioning play
hosts: all
gather_facts: yes

roles:
- launchpad-ppa-webupd8
- tests

- name: tests play
hosts: all
gather_facts: yes
tags: test

roles:
- { role: tests,
when: idempotence is defined and idempotence }
25 changes: 19 additions & 6 deletions tests/test_idempotence.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# Bash script to run idempotence tests.
#
# version: 1.2
# version: 1.4
#
# usage:
#
Expand All @@ -12,6 +12,7 @@
# options:
#
# --box The name of the Vagrant box or host name
# --env The name of the test environment
# --inventory The Ansible inventory in the form of a file or string "host,"
# --playbook The path to the Ansible test playbook
#
Expand All @@ -22,10 +23,17 @@
#
# # on a Vagrant box
# bash test_idempotence.sh \
# --box precise64
# --box precise64.vagrant.dev
# --inventory .vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory
#
#
# changelog:
#
# v1.4 : 10 Jul 2015
# - added extra variables to force running idempotence tests on vagrant
# v1.2
# - added env option
#
# author(s):
# - Pedro Salgado <[email protected]>
#
Expand Down Expand Up @@ -56,6 +64,11 @@ key="$1"
BOX="$2"
shift;;

--env)
# the test environment
ENV="$2"
shift;;

--inventory)
# the Ansible inventory in the form of a file or string "host,"
INVENTORY="$2"
Expand Down Expand Up @@ -85,13 +98,13 @@ LOGFILE="log/${BOX}_${VIRTUALENV_NAME}.log"

EXTRA_ARGS=''
if [ $BOX == "localhost" ]; then
EXTRA_ARGS="--connection=local --extra-vars idempotence=yes"
EXTRA_ARGS="--connection=local --extra-vars idempotence=yes --extra-vars env=${ENV}"
else
EXTRA_ARGS="--u vagrant"
EXTRA_ARGS="--u vagrant --extra-vars idempotence=yes --extra-vars env=vagrant"
fi

echo "[INFO] ${BOX} ${VIRTUALENV_NAME} running idempotence test..."
ansible-playbook -i ${INVENTORY} --limit ${BOX}, ${PLAYBOOK} ${EXTRA_ARGS} 2>&1 | tee ${LOGFILE} | \
ansible-playbook -i ${INVENTORY} --limit ${BOX}, ${EXTRA_ARGS} ${PLAYBOOK} 2>&1 | tee ${LOGFILE} | \
grep "${BOX}" | grep -q "${PASS_CRITERIA}" && \
echo -ne "[TEST] ${BOX} ${VIRTUALENV_NAME} idempotence : ${GREEN}PASS${NC}\n" || \
(echo -ne "[TEST] ${BOX} ${VIRTUALENV_NAME} idempotence : ${RED}FAILED${NC} ${PASS_CRITERIA}\n" && exit 1)
(echo -ne "[TEST] ${BOX} ${VIRTUALENV_NAME} idempotence : ${RED}FAILED${NC} ${PASS_CRITERIA}\n" && cat ${LOGFILE} && exit 1)
8 changes: 5 additions & 3 deletions tests/vagrant.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
# $ bash vagrant.sh --box precise64.vagrant.dev
#
#
# changelog:
#
# v1.4 : 10 Jul 2015
# - remove environment variable ANSIBLE_ASK_SUDO_PASS
#
# author(s):
# - Pedro Salgado <[email protected]>
#
Expand All @@ -23,9 +28,6 @@ DIR="$(dirname "$0")"

cd $DIR

# force Ansible to ask for sudo password when running tests against Vagrant
ANSIBLE_ASK_SUDO_PASS=True

# the path to the Ansible inventory generated by Vagrant
INVENTORY=${DIR}/.vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory

Expand Down
17 changes: 11 additions & 6 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
[tox]
envlist =
# {py27}-{ansible1901,ansible184,ansible172,ansible1610,ansible155,ansible145,ansible134,ansible123}
{py27}-{ansible1901,ansible184}
# {py27}-{ansible192,ansible184,ansible172,ansible1610,ansible155,ansible145,ansible134,ansible123}
{py27}-{ansible192,ansible184,ansible172}

skipsdist = True


[testenv]
changedir = tests
deps =
travis: ansible==1.9.0.1
ansible1901: ansible==1.9.0.1
travis: ansible==1.9.2
ansible192: ansible==1.9.2
ansible184: ansible==1.8.4

passenv = ANSIBLE_ASK_SUDO_PASS HOME

commands =
bash -c "test -s ../requirements.yml && ansible-galaxy install --force -r ../requirements.yml || true"
bash vagrant.sh {posargs}
Expand All @@ -21,10 +24,12 @@ whitelist_externals =


[testenv:travis]
passenv = ANSIBLE_ASK_SUDO_PASS HOME TRAVIS

commands =
bash -c "test -s ../requirements.yml && ansible-galaxy install --force -r ../requirements.yml || true"
ansible-playbook -i localhost, --connection=local test.yml
bash test_idempotence.sh
ansible-playbook -i localhost, --connection=local test.yml {posargs} --skip-tags=test
bash test_idempotence.sh --env travis

whitelist_externals =
ansible-playbook
Expand Down

0 comments on commit f85d199

Please sign in to comment.