diff --git a/.travis.yml b/.travis.yml index 0253d7d..15ed377 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,49 +1,45 @@ sudo: required + env: - - > - container_id=$(mktemp) - distribution=centos - version=7 - init=/usr/lib/systemd/systemd - run_opts="--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro" - - > - container_id=$(mktemp) - distribution=ubuntu - version=14.04 - init=/sbin/init - run_opts="" + # CentOS 7. + - container_id: $(mktemp) + distribution: centos + version: 7 + init: /usr/lib/systemd/systemd + run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro" + # Ubuntu 14.04. + - container_id: $(mktemp) + distribution: ubuntu + version: 14.04 + init: /sbin/init + run_opts: "" services: - docker before_install: - sudo apt-get update - # Pull container - - sudo docker pull ${distribution}:${version} - # Customize container - - sudo docker build --rm=true --file=tests/Dockerfile.${distribution} --tag=${distribution}:ansible tests + # Pull container. + - "sudo docker pull ${distribution}:${version}" + # Customize container. + - "sudo docker build --rm=true --file=tests/Dockerfile.${distribution} --tag=${distribution}:ansible tests" script: - # - # Run test playbook - # - - # Run container in detached state + # Run container in detached state. - sudo docker run --detach --volume="${PWD}":/etc/ansible/roles/role_under_test:ro ${run_opts} ${distribution}:ansible "${init}" > "${container_id}" - # 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 - # Test role - - sudo docker exec --tty "$(cat ${container_id})" env TERM=xterm ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml - # Idempotence test + # 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' + + # 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. - > sudo docker exec "$(cat ${container_id})" ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml | grep -q 'changed=0.*failed=0' && (echo 'Idempotence test: pass' && exit 0) || (echo 'Idempotence test: fail' && exit 1) - # Clean up - - sudo docker stop "$(cat ${container_id})" - -notifications: - email: false + # Clean up + - 'sudo docker stop "$(cat ${container_id})"' diff --git a/tests/Dockerfile.centos b/tests/Dockerfile.centos index 888d502..8aa0654 100644 --- a/tests/Dockerfile.centos +++ b/tests/Dockerfile.centos @@ -1,4 +1,5 @@ FROM centos:7 + # Install systemd -- See https://hub.docker.com/_/centos/ RUN yum -y swap -- remove fakesystemd -- install systemd systemd-libs RUN yum -y update; yum clean all; \ @@ -10,14 +11,17 @@ rm -f /lib/systemd/system/sockets.target.wants/*udev*; \ rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \ rm -f /lib/systemd/system/basic.target.wants/*; \ rm -f /lib/systemd/system/anaconda.target.wants/*; + # Install Ansible RUN yum -y install epel-release RUN yum -y install git ansible sudo RUN yum clean all + # Disable requiretty RUN sed -i -e 's/^\(Defaults\s*requiretty\)/#--- \1/' /etc/sudoers + # Install Ansible inventory file RUN echo -e '[local]\nlocalhost ansible_connection=local' > /etc/ansible/hosts -VOLUME [ "/sys/fs/cgroup" ] -CMD ["/usr/sbin/init"] +VOLUME ["/sys/fs/cgroup"] +CMD ["/usr/sbin/init"] diff --git a/tests/Dockerfile.ubuntu b/tests/Dockerfile.ubuntu index 3dd5383..1475a46 100644 --- a/tests/Dockerfile.ubuntu +++ b/tests/Dockerfile.ubuntu @@ -1,9 +1,10 @@ FROM ubuntu:14.04 + # Install Ansible RUN apt-get install -y software-properties-common git RUN apt-add-repository -y ppa:ansible/ansible RUN apt-get update RUN apt-get install -y ansible + # Install Ansible inventory file RUN echo "[local]\nlocalhost ansible_connection=local" > /etc/ansible/hosts - diff --git a/tests/test.yml b/tests/test.yml index 1edb57a..f5c5ca6 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -1,5 +1,6 @@ --- - hosts: all + vars: apache_listen_port_ssl: 443 apache_create_vhosts: true @@ -7,5 +8,6 @@ apache_vhosts: - servername: "example.com" documentroot: "/var/www/vhosts/example_com" + roles: - role_under_test