Skip to content

Commit 44bf43e

Browse files
Introduce mutli platform .travis
1 parent 40249c2 commit 44bf43e

File tree

5 files changed

+92
-45
lines changed

5 files changed

+92
-45
lines changed

.travis.yml

Lines changed: 68 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,77 @@
1-
---
2-
language: python
3-
python: "2.7"
1+
sudo: required
42

53
env:
6-
- SITE=playbook.yml
4+
global:
5+
# https://github.com/travis-ci/travis-ci/issues/6461#issuecomment-239577306
6+
DOCKER_VERSION: "1.9.1-0~trusty"
7+
matrix:
8+
- distro: ernestasposkus/centos7
9+
init: /usr/lib/systemd/systemd
10+
run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro"
11+
- distro: ernestasposkus/centos6
12+
init: /sbin/init
13+
run_opts: ""
14+
- distro: ernestasposkus/ubuntu1604
15+
init: /lib/systemd/systemd
16+
run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro"
17+
- distro: ernestasposkus/ubuntu1404
18+
init: /sbin/init
19+
run_opts: ""
720

8-
before_install:
9-
- sudo apt-get update -qq
10-
- sudo apt-get install curl -y
21+
services:
22+
- docker
1123

12-
install:
13-
- pip install -U ansible
24+
before_install:
25+
# Downgrade to specific version of Docker engine.
26+
- sudo apt-get update
27+
- sudo apt-get remove docker-engine -yq
28+
- sudo apt-get install docker-engine=$DOCKER_VERSION -yq --no-install-suggests --no-install-recommends --force-yes -o Dpkg::Options::="--force-confnew"
1429

15-
# Add ansible.cfg to pick up roles path.
16-
- "{ echo '[defaults]'; echo 'roles_path = ../'; } >> ansible.cfg"
30+
# Pull container.
31+
- 'sudo docker pull ${distro}:latest'
1732

1833
script:
19-
# Check the role/playbook's syntax.
20-
- "ansible-playbook -i tests/inventory tests/$SITE --syntax-check"
34+
- container_id=$(mktemp)
35+
# Run container in detached state.
36+
- 'sudo docker run --detach --volume="${PWD}":/etc/ansible/roles/role_under_test:ro ${run_opts} ${distro}:latest "${init}" > "${container_id}"'
37+
38+
# Inspect docker container
39+
- 'sudo docker inspect $(cat ${container_id})'
40+
41+
# Print ansible version
42+
- 'sudo docker exec --tty "$(cat ${container_id})" env TERM=xterm ansible --version'
43+
44+
# Check Ansible host setup
45+
- 'sudo docker exec --tty "$(cat ${container_id})" env TERM=xterm ansible all -i "localhost," -c local -m setup'
46+
47+
# Install dependencies
48+
- 'sudo docker exec --tty "$(cat ${container_id})" env TERM=xterm ansible-galaxy install geerlingguy.java'
49+
- 'sudo docker exec --tty "$(cat ${container_id})" env TERM=xterm ansible-galaxy install AnsibleShipyard.ansible-zookeeper'
50+
- 'sudo docker exec --tty "$(cat ${container_id})" env TERM=xterm ansible-playbook /etc/ansible/roles/role_under_test/tests/dependencies.yml'
51+
52+
# Ansible syntax check.
53+
- 'sudo docker exec --tty "$(cat ${container_id})" env TERM=xterm ansible-playbook /etc/ansible/roles/role_under_test/tests/playbook.yml --syntax-check'
54+
55+
# Test role.
56+
- 'sudo docker exec --tty "$(cat ${container_id})" env TERM=xterm ansible-playbook /etc/ansible/roles/role_under_test/tests/playbook.yml'
57+
58+
# Test role idempotence.
59+
- idempotence=$(mktemp)
60+
- sudo docker exec "$(cat ${container_id})" ansible-playbook /etc/ansible/roles/role_under_test/tests/playbook.yml | tee -a ${idempotence}
61+
- >
62+
tail ${idempotence}
63+
| grep -q 'changed=0.*failed=0'
64+
&& (echo 'Idempotence test: pass' && exit 0)
65+
|| (echo 'Idempotence test: fail' && exit 1)
66+
67+
# Test role.
68+
- 'sudo docker exec --tty "$(cat ${container_id})" env TERM=xterm ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml'
69+
70+
# View container logs
71+
- 'sudo docker logs "$(cat ${container_id})"'
2172

22-
# Run the role/playbook with ansible-playbook.
23-
- "ansible-playbook -i tests/inventory tests/playbook.yml --connection=local --sudo"
73+
# Clean up.
74+
- 'sudo docker stop "$(cat ${container_id})"'
2475

25-
# Healthcheck
26-
# - "curl http://localhost:5050/"
76+
notifications:
77+
webhooks: https://galaxy.ansible.com/api/v1/notifications/ - "curl http://localhost:5050/"

tests/dependencies.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
- hosts: localhost
3+
connection: local
4+
remote_user: root
5+
roles:
6+
- role: geerlingguy.java
7+
- role: AnsibleShipyard.ansible-zookeeper

tests/main.yml

Lines changed: 0 additions & 18 deletions
This file was deleted.

tests/playbook.yml

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
11
---
2-
#
3-
# Test Playbook
4-
#
5-
62
- hosts: localhost
73
connection: local
8-
sudo: yes
9-
4+
remote_user: root
105
roles:
11-
- {role: ../../, mesos_install_mode: "master-slave"}
12-
13-
- include: main.yml
14-
6+
- role: role_under_test
7+
mesos_install_mode: "master-slave"

tests/test.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
- hosts: localhost
3+
connection: local
4+
remote_user: root
5+
tasks:
6+
- shell: "ps aux | grep -i mesos"
7+
register: status
8+
failed_when: status.rc != 0
9+
when: ansible_service_mgr != 'systemd'
10+
11+
- shell: "systemctl status mesos-master | grep running"
12+
register: status
13+
failed_when: status.rc != 0
14+
when: ansible_service_mgr == 'systemd'

0 commit comments

Comments
 (0)