-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path.travis.yml
61 lines (50 loc) · 1.76 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
59
60
61
---
# Sudo is required for some docker commands
sudo: required
services:
- docker
# Run tests for each supported OS
#
# distro: Distro name corresponding to docker images
# init: The init system corresponding to the distro
# run_opts: Additional arguments to pass when creating the docker container
env:
- distro: ubuntu1604
init: /lib/systemd/systemd
run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro"
# Provision docker container
before_install:
# Pull latest version of the docker image
- 'docker pull cdriehuys/docker-${distro}-ansible:latest'
# Create random file to store container ID
- container_id=$(mktemp)
# Run container with role mounted inside
- >
docker run --detach --volume="${PWD}":/etc/ansible/roles/role_under_test:ro
${run_opts} cdriehuys/docker-${distro}-ansible:latest
"${init}" > "${container_id}"
# Start docker container and run tests
script:
# Test role syntax
- >
docker exec --tty "$(cat ${container_id})" env TERM=xterm
ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml --syntax-check
# Run role first time
- >
docker exec --tty "$(cat ${container_id})" env TERM=xterm
ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml
# Create temp file for idempotency test results
- idempotence=$(mktemp)
# Run role a second time
- >
docker exec "$(cat ${container_id})"
ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml
| tee -a ${idempotence}
# Make sure second run didn't change anything
- >
tail ${idempotence}
| grep -q 'changed=0.*failed=0'
&& (echo 'Idempotence test: pass' && exit 0)
|| (echo 'Idempotence test: fail' && exit 1)
notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/