From 4f893912bbaa57ba8991cfdfce8ea83c93e8f4c1 Mon Sep 17 00:00:00 2001 From: Jeff Geerling Date: Tue, 13 Sep 2016 21:09:24 -0500 Subject: [PATCH] Use modern Docker multi-OS tests. --- .travis.yml | 47 ++++++++++++++++++++++++++++++----------------- README.md | 2 +- tests/inventory | 1 - tests/test.yml | 6 +++--- 4 files changed, 34 insertions(+), 22 deletions(-) delete mode 100644 tests/inventory diff --git a/.travis.yml b/.travis.yml index 11a7369..506330a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,34 +1,47 @@ --- 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: "" + +services: + - docker before_install: - - sudo apt-get update -qq - -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) +after_success: + # Clean up. + - 'sudo docker stop "$(cat ${container_id})"' + notifications: webhooks: https://galaxy.ansible.com/api/v1/notifications/ diff --git a/README.md b/README.md index 404c853..8fa06e8 100644 --- a/README.md +++ b/README.md @@ -77,4 +77,4 @@ MIT / BSD ## Author Information -This role was created in 2014 by [Jeff Geerling](http://jeffgeerling.com/), author of [Ansible for DevOps](http://ansiblefordevops.com/). +This role was created in 2014 by [Jeff Geerling](http://www.jeffgeerling.com/), author of [Ansible for DevOps](https://www.ansiblefordevops.com/). diff --git a/tests/inventory b/tests/inventory deleted file mode 100644 index 2fbb50c..0000000 --- a/tests/inventory +++ /dev/null @@ -1 +0,0 @@ -localhost diff --git a/tests/test.yml b/tests/test.yml index 63f8266..3646ff4 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -1,5 +1,5 @@ --- -- hosts: localhost - remote_user: root +- hosts: all + roles: - - ansible-role-munin + - role_under_test