Modern Docker multi-OS test layout.

pull/69/head
Jeff Geerling 8 years ago
parent a767f2741c
commit 5fc63d4a6f
  1. 56
      .travis.yml
  2. 1
      tests/inventory
  3. 10
      tests/test.yml

@ -1,39 +1,53 @@
---
sudo: required
language: python
python: "2.7"
env:
- SITE=test.yml
- distro: centos7
init: /usr/lib/systemd/systemd
run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro"
- distro: ubuntu1604
init: /lib/systemd/systemd
run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro"
- distro: ubuntu1404
init: /sbin/init
run_opts: ""
- distro: ubuntu1204
init: /sbin/init
run_opts: ""
services:
- docker
before_install:
- sudo apt-get update -qq
- sudo apt-get install -y curl
install:
# Install Ansible.
- pip install ansible
# Add ansible.cfg to pick up roles path.
- "{ echo '[defaults]'; echo 'roles_path = ../'; } >> ansible.cfg"
# Pull container
- 'sudo docker pull geerlingguy/docker-${distro}-ansible:latest'
script:
# Check the role/playbook's syntax.
- "ansible-playbook -i tests/inventory tests/$SITE --syntax-check"
- container_id=$(mktemp)
# Run container in detached state.
- 'sudo docker run --detach --volume="${PWD}":/etc/ansible/roles/role_under_test:ro ${run_opts} geerlingguy/docker-${distro}-ansible:latest "${init}" > "${container_id}"'
# Run the role/playbook with ansible-playbook.
- "ansible-playbook -i tests/inventory tests/$SITE --connection=local --sudo"
# Ansible syntax check.
- 'sudo docker exec --tty "$(cat ${container_id})" env TERM=xterm ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml --syntax-check'
# Run the role/playbook again, checking to make sure it's idempotent.
# Test role.
- 'sudo docker exec --tty "$(cat ${container_id})" env TERM=xterm ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml'
# Test role idempotence.
- idempotence=$(mktemp)
- sudo docker exec "$(cat ${container_id})" ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml | tee -a ${idempotence}
- >
ansible-playbook -i tests/inventory tests/$SITE --connection=local --sudo
tail ${idempotence}
| grep -q 'changed=0.*failed=0'
&& (echo 'Idempotence test: pass' && exit 0)
|| (echo 'Idempotence test: fail' && exit 1)
# TODO - get the test working. Probably need to add a virtual host.
# Request a page via Nginx, to make sure Nginx is running and responds.
# - "curl http://localhost/"
# Check if nginx is running.
# TODO
after_success:
# Clean up.
- 'sudo docker stop "$(cat ${container_id})"'
notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/

@ -1 +0,0 @@
localhost

@ -1,6 +1,8 @@
---
- hosts: localhost
remote_user: root
- hosts: all
vars:
nginx_use_ppa: true
roles:
- role: ansible-role-nginx
nginx_use_ppa: true
- role_under_test