|
1 |
| ---- |
2 |
| -language: python |
3 |
| -python: "2.7" |
| 1 | +sudo: required |
4 | 2 |
|
5 | 3 | 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: "" |
7 | 20 |
|
8 |
| -before_install: |
9 |
| - - sudo apt-get update -qq |
10 |
| - - sudo apt-get install curl -y |
| 21 | +services: |
| 22 | + - docker |
11 | 23 |
|
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" |
14 | 29 |
|
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' |
17 | 32 |
|
18 | 33 | 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})"' |
21 | 72 |
|
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})"' |
24 | 75 |
|
25 |
| - # Healthcheck |
26 |
| - # - "curl http://localhost:5050/" |
| 76 | +notifications: |
| 77 | + webhooks: https://galaxy.ansible.com/api/v1/notifications/ - "curl http://localhost:5050/" |
0 commit comments