diff --git a/.travis.yml b/.travis.yml index 2afc404..9c4878b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,30 +1,76 @@ --- -language: python -python: "2.7" -# Use the new container infrastructure sudo: required -# Install ansible -addons: - apt: - packages: - - python-pip -install: - # Install ansible - - pip install ansible - # Check ansible version - - ansible --version - # Create ansible.cfg with correct roles_path - - printf '[defaults]\nroles_path=../' >ansible.cfg +services: + - docker +env: + - distribution: centos + version: 6 + playbook: opensource + - distribution: centos + version: 6 + playbook: template + - distribution: centos + version: 6 + playbook: push + - distribution: centos + version: 7 + playbook: opensource + - distribution: centos + version: 7 + playbook: template + - distribution: centos + version: 7 + playbook: push + - distribution: debian + version: jessie + playbook: opensource + - distribution: debian + version: jessie + playbook: template + - distribution: debian + version: jessie + playbook: push + - distribution: debian + version: stretch + playbook: opensource + - distribution: debian + version: stretch + playbook: template + - distribution: debian + version: stretch + playbook: push + - distribution: ubuntu + version: trusty + playbook: opensource + - distribution: ubuntu + version: trusty + playbook: template + - distribution: ubuntu + version: trusty + playbook: push + - distribution: ubuntu + version: xenial + playbook: opensource + - distribution: ubuntu + version: xenial + playbook: template + - distribution: ubuntu + version: xenial + playbook: push +before_install: + - 'sudo docker pull ${distribution}:${version}' + - 'sudo docker build --no-cache --rm --file=tests/dockerfiles/Dockerfile.${distribution}-${version} --tag=${distribution}-${version}:ansible tests' script: - # Basic role syntax check - - ansible-playbook tests/test.yml -i tests/inventory --syntax-check - # Run the role with ansible-playbook. - - ansible-playbook tests/test.yml -i tests/inventory --connection=local --become - # Run the role again, checking to make sure it's idempotent. + - container_id=$(mktemp) + - 'sudo docker run --detach --privileged -v /sys/fs/cgroup:/sys/fs/cgroup:ro --volume="${PWD}":/etc/ansible/roles/ansible-role-nginx:ro ${distribution}-${version}:ansible > "${container_id}"' + - 'sudo docker exec "$(cat ${container_id})" env ANSIBLE_FORCE_COLOR=1 ansible-playbook -v /etc/ansible/roles/ansible-role-nginx/tests/playbooks/nginx-${playbook}.yml --syntax-check' + - 'sudo docker exec "$(cat ${container_id})" env ANSIBLE_FORCE_COLOR=1 ansible-playbook -v /etc/ansible/roles/ansible-role-nginx/tests/playbooks/nginx-${playbook}.yml' - > - ansible-playbook tests/test.yml -i tests/inventory --connection=local --become | grep -q 'changed=0.*failed=0' - && (echo 'Idempotence test: pass' && exit 0) || (echo 'Idempotence test: fail' && exit 1) - # Request a page via the web server, to make sure NGINX is running and responds. - - curl http://localhost/ + sudo docker exec "$(cat ${container_id})" env ANSIBLE_FORCE_COLOR=1 ansible-playbook -v /etc/ansible/roles/ansible-role-nginx/tests/playbooks/nginx-${playbook}.yml + | grep -q 'changed=0.*failed=0' + && (echo 'Idempotence test: pass' && exit 0) + || (echo 'Idempotence test: fail' && exit 1) + - 'sudo docker exec "$(cat ${container_id})" curl http://localhost/' + - 'sudo docker rm -f "$(cat ${container_id})"' notifications: webhooks: https://galaxy.ansible.com/api/v1/notifications/ diff --git a/tests/dockerfiles/Dockerfile.centos-6 b/tests/dockerfiles/Dockerfile.centos-6 new file mode 100644 index 0000000..fef4a5e --- /dev/null +++ b/tests/dockerfiles/Dockerfile.centos-6 @@ -0,0 +1,12 @@ +FROM centos:6 + +RUN yum -y install epel-release +RUN yum -y install git ansible sudo + +RUN sed -i -e 's/^\(Defaults\s*requiretty\)/#--- \1/' /etc/sudoers + +RUN echo -e '[local]\nlocalhost ansible_connection=local' > /etc/ansible/hosts + +VOLUME ["/sys/fs/cgroup"] + +CMD ["/sbin/init"] diff --git a/tests/dockerfiles/Dockerfile.centos-7 b/tests/dockerfiles/Dockerfile.centos-7 new file mode 100644 index 0000000..b7c1e90 --- /dev/null +++ b/tests/dockerfiles/Dockerfile.centos-7 @@ -0,0 +1,24 @@ +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; \ +(cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == systemd-tmpfiles-setup.service ] || rm -f $i; done); \ +rm -f /lib/systemd/system/multi-user.target.wants/*; \ +rm -f /etc/systemd/system/*.wants/*; \ +rm -f /lib/systemd/system/local-fs.target.wants/*; \ +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/*; + +RUN yum -y install epel-release +RUN yum -y install git ansible sudo + +RUN sed -i -e 's/^\(Defaults\s*requiretty\)/#--- \1/' /etc/sudoers + +RUN echo -e '[local]\nlocalhost ansible_connection=local' > /etc/ansible/hosts + +VOLUME ["/sys/fs/cgroup"] + +CMD ["/usr/sbin/init"] diff --git a/tests/dockerfiles/Dockerfile.debian-jessie b/tests/dockerfiles/Dockerfile.debian-jessie new file mode 100644 index 0000000..eafadf5 --- /dev/null +++ b/tests/dockerfiles/Dockerfile.debian-jessie @@ -0,0 +1,19 @@ +FROM debian:jessie + +RUN apt-get update -y && apt-get install -y --no-install-recommends \ + software-properties-common \ + build-essential \ + libffi-dev \ + libssl-dev \ + python-dev \ + python-pip \ + git \ + apt-transport-https \ + curl \ + && rm -rf /var/lib/apt/lists/* + +RUN pip install --upgrade setuptools && pip install ansible + +RUN mkdir -p /etc/ansible && echo "[local]\nlocalhost ansible_connection=local" > /etc/ansible/hosts + +ENTRYPOINT ["/sbin/init"] diff --git a/tests/dockerfiles/Dockerfile.debian-stretch b/tests/dockerfiles/Dockerfile.debian-stretch new file mode 100644 index 0000000..1a0e1e3 --- /dev/null +++ b/tests/dockerfiles/Dockerfile.debian-stretch @@ -0,0 +1,22 @@ +FROM debian:stretch + +RUN apt-get update -y && apt-get install -y --no-install-recommends \ + software-properties-common \ + build-essential \ + libffi-dev \ + libssl-dev \ + python-dev \ + python-pip \ + git \ + systemd \ + apt-transport-https \ + curl \ + gnupg2 \ + dirmngr \ + && rm -rf /var/lib/apt/lists/* + +RUN pip install --upgrade setuptools && pip install ansible + +RUN mkdir -p /etc/ansible && echo "[local]\nlocalhost ansible_connection=local" > /etc/ansible/hosts + +ENTRYPOINT ["/bin/systemd"] diff --git a/tests/dockerfiles/Dockerfile.ubuntu-trusty b/tests/dockerfiles/Dockerfile.ubuntu-trusty new file mode 100644 index 0000000..c36e55e --- /dev/null +++ b/tests/dockerfiles/Dockerfile.ubuntu-trusty @@ -0,0 +1,14 @@ +FROM ubuntu:trusty + +RUN apt-get update && apt-get dist-upgrade -y && apt-get install -y software-properties-common && rm -rf /var/lib/apt/lists/* + +RUN apt-add-repository -y ppa:ansible/ansible && apt-get update && apt-get install -y \ + git \ + ansible \ + apt-transport-https \ + curl \ + && rm -rf /var/lib/apt/lists/* + +RUN echo "[local]\nlocalhost ansible_connection=local" > /etc/ansible/hosts + +ENTRYPOINT ["/sbin/init"] diff --git a/tests/dockerfiles/Dockerfile.ubuntu-xenial b/tests/dockerfiles/Dockerfile.ubuntu-xenial new file mode 100644 index 0000000..f8ad055 --- /dev/null +++ b/tests/dockerfiles/Dockerfile.ubuntu-xenial @@ -0,0 +1,14 @@ +FROM ubuntu:xenial + +RUN apt-get update && apt-get dist-upgrade -y && apt-get install -y software-properties-common && rm -rf /var/lib/apt/lists/* + +RUN apt-add-repository -y ppa:ansible/ansible && apt-get update && apt-get install -y \ + git \ + ansible \ + apt-transport-https \ + curl \ + && rm -rf /var/lib/apt/lists/* + +RUN echo "[local]\nlocalhost ansible_connection=local" > /etc/ansible/hosts + +ENTRYPOINT ["/sbin/init"] diff --git a/tests/files/http/default.conf b/tests/files/http/default.conf new file mode 100644 index 0000000..cb80625 --- /dev/null +++ b/tests/files/http/default.conf @@ -0,0 +1,44 @@ +server { + listen 8080; + server_name localhost; + + #charset koi8-r; + #access_log /var/log/nginx/host.access.log main; + + location / { + root /usr/share/nginx/html; + index index.html index.htm; + } + + #error_page 404 /404.html; + + # redirect server error pages to the static page /50x.html + # + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root /usr/share/nginx/html; + } + + # proxy the PHP scripts to Apache listening on 127.0.0.1:80 + # + #location ~ \.php$ { + # proxy_pass http://127.0.0.1; + #} + + # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 + # + #location ~ \.php$ { + # root html; + # fastcgi_pass 127.0.0.1:9000; + # fastcgi_index index.php; + # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; + # include fastcgi_params; + #} + + # deny access to .htaccess files, if Apache's document root + # concurs with nginx's one + # + #location ~ /\.ht { + # deny all; + #} +} diff --git a/tests/files/nginx.conf b/tests/files/nginx.conf new file mode 100644 index 0000000..ba09f41 --- /dev/null +++ b/tests/files/nginx.conf @@ -0,0 +1,31 @@ +user nginx; +worker_processes 4; + +error_log /var/log/nginx/error.log warn; +pid /var/run/nginx.pid; + + +events { + worker_connections 1024; +} + + +http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + + access_log /var/log/nginx/access.log main; + + sendfile on; + #tcp_nopush on; + + keepalive_timeout 65; + + #gzip on; + + include /etc/nginx/conf.d/*.conf; +} 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/playbooks/nginx-opensource.yml similarity index 83% rename from tests/test.yml rename to tests/playbooks/nginx-opensource.yml index 42bba2c..25ce5e7 100644 --- a/tests/test.yml +++ b/tests/playbooks/nginx-opensource.yml @@ -1,5 +1,6 @@ --- - hosts: localhost + become: true remote_user: root roles: - ansible-role-nginx diff --git a/tests/playbooks/nginx-push.yml b/tests/playbooks/nginx-push.yml new file mode 100644 index 0000000..92b753b --- /dev/null +++ b/tests/playbooks/nginx-push.yml @@ -0,0 +1,11 @@ +--- +- hosts: localhost + become: true + remote_user: root + roles: + - ansible-role-nginx + vars: + main_push_enable: true + main_push_location: ../files/nginx.conf + http_push_enable: true + http_push_location: ../files/http/*.conf diff --git a/tests/playbooks/nginx-template.yml b/tests/playbooks/nginx-template.yml new file mode 100644 index 0000000..1c95862 --- /dev/null +++ b/tests/playbooks/nginx-template.yml @@ -0,0 +1,10 @@ +--- +- hosts: localhost + become: true + remote_user: root + roles: + - ansible-role-nginx + vars: + http_template_enable: true + http_template_keepalive_timeout: 70 + http_template_listen: 82