forked from CyVerse-Ansible/ansible-role-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.travis.yml
58 lines (49 loc) · 1.9 KB
/
.travis.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
---
language: python
python: "2.7"
sudo: required
dist: trusty
services:
- docker
env:
- distribution: centos
version: 7
- distribution: centos
version: 6
# No supported/sane way to run Ansible inside a CentOS 5 Docker container;
# - distribution: centos
# version: 5
- distribution: ubuntu
version: 16.04
- distribution: ubuntu
version: 14.04
- distribution: ubuntu
version: 12.04
before_install:
- 'sudo docker run -it --name=test_dummy --privileged --detach --volume="${PWD}":/etc/ansible/roles/role_under_test:rw cyverse/ansible-test:latest-${distribution}-${version} bash'
script:
# 1. Syntax check
- "sudo docker exec test_dummy ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml -i tests/inventory --syntax-check"
# 2. Run playbook to execute role
- "sudo docker exec test_dummy ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml -i tests/inventory --connection=local"
# 3. HERE, WRITE SOME TESTS to verify that your role has produced the desired
# effect on the target system. Your tests should be bash commands that
# complete with an exit status of 0 for a pass, and non-zero for a failure.
#
# This example tests whether 'hello' exists in /tmp/hello.txt.
# - >
# sudo docker exec test_dummy bash -c cat /tmp/hello.txt | grep -q 'hello'
# && (echo 'Test for role result: pass' && exit 0)
# || (echo 'Test for role result: fail' && exit 1)
# 4. Idempotence test (run playbook again to confirm nothing changes)
- >
sudo docker exec test_dummy ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml -i tests/inventory --connection=local
| grep -q 'changed=0.*failed=0'
&& (echo 'Idempotence test: pass' && exit 0)
|| (echo 'Idempotence test: fail' && exit 1)
notifications:
webhooks:
urls:
- https://galaxy.ansible.com/api/v1/notifications
on_success: always
on_failure: never