From 2b72889d9075594da07cbbaef65761fda779ded4 Mon Sep 17 00:00:00 2001 From: Alessandro Fael Garcia Date: Fri, 13 Apr 2018 15:24:09 -0700 Subject: [PATCH 01/11] Test role across multiple distributions Implement support to test the role in multiple Linux distributions by deploying Docker containers within Travis --- .travis.yml | 52 +++++++++++---------- tests/dockerfiles/Dockerfile.centos-6 | 12 +++++ tests/dockerfiles/Dockerfile.centos-7 | 24 ++++++++++ tests/dockerfiles/Dockerfile.debian-jessie | 17 +++++++ tests/dockerfiles/Dockerfile.debian-stretch | 18 +++++++ tests/dockerfiles/Dockerfile.ubuntu-trusty | 12 +++++ tests/dockerfiles/Dockerfile.ubuntu-xenial | 12 +++++ 7 files changed, 123 insertions(+), 24 deletions(-) create mode 100644 tests/dockerfiles/Dockerfile.centos-6 create mode 100644 tests/dockerfiles/Dockerfile.centos-7 create mode 100644 tests/dockerfiles/Dockerfile.debian-jessie create mode 100644 tests/dockerfiles/Dockerfile.debian-stretch create mode 100644 tests/dockerfiles/Dockerfile.ubuntu-trusty create mode 100644 tests/dockerfiles/Dockerfile.ubuntu-xenial diff --git a/.travis.yml b/.travis.yml index 2afc404..0f32d06 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,30 +1,34 @@ --- -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 + - distribution: centos + version: 7 + - distribution: ubuntu + version: trusty + - distribution: ubuntu + version: xenial + - distribution: debian + version: jessie + - distribution: debian + version: stretch +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/test.yml --syntax-check' + - 'sudo docker exec "$(cat ${container_id})" env ANSIBLE_FORCE_COLOR=1 ansible-playbook -v /etc/ansible/roles/ansible-role-nginx/tests/test.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/test.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..164d3cd --- /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 ["/usr/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..8d38f0c --- /dev/null +++ b/tests/dockerfiles/Dockerfile.debian-jessie @@ -0,0 +1,17 @@ +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 \ + && 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..ee2fbc7 --- /dev/null +++ b/tests/dockerfiles/Dockerfile.debian-stretch @@ -0,0 +1,18 @@ +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 \ + && 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..c9687d2 --- /dev/null +++ b/tests/dockerfiles/Dockerfile.ubuntu-trusty @@ -0,0 +1,12 @@ +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 \ + && 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..2faaba1 --- /dev/null +++ b/tests/dockerfiles/Dockerfile.ubuntu-xenial @@ -0,0 +1,12 @@ +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 \ + && rm -rf /var/lib/apt/lists/* + +RUN echo "[local]\nlocalhost ansible_connection=local" > /etc/ansible/hosts + +ENTRYPOINT ["/sbin/init"] From 51cd432317033008967de19a1108d19743d2e8fb Mon Sep 17 00:00:00 2001 From: Alessandro Fael Garcia Date: Fri, 13 Apr 2018 15:53:19 -0700 Subject: [PATCH 02/11] Fix Dockerfiles * Install apt-transport-https depency in Debian based containers * Test different CMD instruction in CentOS 6 container --- tests/dockerfiles/Dockerfile.centos-6 | 2 +- tests/dockerfiles/Dockerfile.debian-jessie | 1 + tests/dockerfiles/Dockerfile.debian-stretch | 1 + tests/dockerfiles/Dockerfile.ubuntu-trusty | 1 + tests/dockerfiles/Dockerfile.ubuntu-xenial | 1 + 5 files changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/dockerfiles/Dockerfile.centos-6 b/tests/dockerfiles/Dockerfile.centos-6 index 164d3cd..fef4a5e 100644 --- a/tests/dockerfiles/Dockerfile.centos-6 +++ b/tests/dockerfiles/Dockerfile.centos-6 @@ -9,4 +9,4 @@ RUN echo -e '[local]\nlocalhost ansible_connection=local' > /etc/ansible/hosts VOLUME ["/sys/fs/cgroup"] -CMD ["/usr/sbin/init"] +CMD ["/sbin/init"] diff --git a/tests/dockerfiles/Dockerfile.debian-jessie b/tests/dockerfiles/Dockerfile.debian-jessie index 8d38f0c..b63e28f 100644 --- a/tests/dockerfiles/Dockerfile.debian-jessie +++ b/tests/dockerfiles/Dockerfile.debian-jessie @@ -8,6 +8,7 @@ RUN apt-get update -y && apt-get install -y --no-install-recommends \ python-dev \ python-pip \ git \ + apt-transport-https && rm -rf /var/lib/apt/lists/* RUN pip install --upgrade setuptools && pip install ansible diff --git a/tests/dockerfiles/Dockerfile.debian-stretch b/tests/dockerfiles/Dockerfile.debian-stretch index ee2fbc7..8481241 100644 --- a/tests/dockerfiles/Dockerfile.debian-stretch +++ b/tests/dockerfiles/Dockerfile.debian-stretch @@ -9,6 +9,7 @@ RUN apt-get update -y && apt-get install -y --no-install-recommends \ python-pip \ git \ systemd \ + apt-transport-https && rm -rf /var/lib/apt/lists/* RUN pip install --upgrade setuptools && pip install ansible diff --git a/tests/dockerfiles/Dockerfile.ubuntu-trusty b/tests/dockerfiles/Dockerfile.ubuntu-trusty index c9687d2..3d3466a 100644 --- a/tests/dockerfiles/Dockerfile.ubuntu-trusty +++ b/tests/dockerfiles/Dockerfile.ubuntu-trusty @@ -5,6 +5,7 @@ RUN apt-get update && apt-get dist-upgrade -y && apt-get install -y software-pro RUN apt-add-repository -y ppa:ansible/ansible && apt-get update && apt-get install -y \ git \ ansible \ + apt-transport-https && rm -rf /var/lib/apt/lists/* RUN echo "[local]\nlocalhost ansible_connection=local" > /etc/ansible/hosts diff --git a/tests/dockerfiles/Dockerfile.ubuntu-xenial b/tests/dockerfiles/Dockerfile.ubuntu-xenial index 2faaba1..d5457d3 100644 --- a/tests/dockerfiles/Dockerfile.ubuntu-xenial +++ b/tests/dockerfiles/Dockerfile.ubuntu-xenial @@ -5,6 +5,7 @@ RUN apt-get update && apt-get dist-upgrade -y && apt-get install -y software-pro RUN apt-add-repository -y ppa:ansible/ansible && apt-get update && apt-get install -y \ git \ ansible \ + apt-transport-https && rm -rf /var/lib/apt/lists/* RUN echo "[local]\nlocalhost ansible_connection=local" > /etc/ansible/hosts From cb33749393f5bbb46c8bce6b4870127f41ecce23 Mon Sep 17 00:00:00 2001 From: Alessandro Fael Garcia Date: Fri, 13 Apr 2018 15:59:19 -0700 Subject: [PATCH 03/11] Fix Dockerfiles syntax --- tests/dockerfiles/Dockerfile.debian-jessie | 2 +- tests/dockerfiles/Dockerfile.debian-stretch | 2 +- tests/dockerfiles/Dockerfile.ubuntu-trusty | 2 +- tests/dockerfiles/Dockerfile.ubuntu-xenial | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/dockerfiles/Dockerfile.debian-jessie b/tests/dockerfiles/Dockerfile.debian-jessie index b63e28f..edafeac 100644 --- a/tests/dockerfiles/Dockerfile.debian-jessie +++ b/tests/dockerfiles/Dockerfile.debian-jessie @@ -8,7 +8,7 @@ RUN apt-get update -y && apt-get install -y --no-install-recommends \ python-dev \ python-pip \ git \ - apt-transport-https + apt-transport-https \ && rm -rf /var/lib/apt/lists/* RUN pip install --upgrade setuptools && pip install ansible diff --git a/tests/dockerfiles/Dockerfile.debian-stretch b/tests/dockerfiles/Dockerfile.debian-stretch index 8481241..5cb8157 100644 --- a/tests/dockerfiles/Dockerfile.debian-stretch +++ b/tests/dockerfiles/Dockerfile.debian-stretch @@ -9,7 +9,7 @@ RUN apt-get update -y && apt-get install -y --no-install-recommends \ python-pip \ git \ systemd \ - apt-transport-https + apt-transport-https \ && rm -rf /var/lib/apt/lists/* RUN pip install --upgrade setuptools && pip install ansible diff --git a/tests/dockerfiles/Dockerfile.ubuntu-trusty b/tests/dockerfiles/Dockerfile.ubuntu-trusty index 3d3466a..4223f20 100644 --- a/tests/dockerfiles/Dockerfile.ubuntu-trusty +++ b/tests/dockerfiles/Dockerfile.ubuntu-trusty @@ -5,7 +5,7 @@ RUN apt-get update && apt-get dist-upgrade -y && apt-get install -y software-pro RUN apt-add-repository -y ppa:ansible/ansible && apt-get update && apt-get install -y \ git \ ansible \ - apt-transport-https + apt-transport-https \ && rm -rf /var/lib/apt/lists/* RUN echo "[local]\nlocalhost ansible_connection=local" > /etc/ansible/hosts diff --git a/tests/dockerfiles/Dockerfile.ubuntu-xenial b/tests/dockerfiles/Dockerfile.ubuntu-xenial index d5457d3..56b7c39 100644 --- a/tests/dockerfiles/Dockerfile.ubuntu-xenial +++ b/tests/dockerfiles/Dockerfile.ubuntu-xenial @@ -5,7 +5,7 @@ RUN apt-get update && apt-get dist-upgrade -y && apt-get install -y software-pro RUN apt-add-repository -y ppa:ansible/ansible && apt-get update && apt-get install -y \ git \ ansible \ - apt-transport-https + apt-transport-https \ && rm -rf /var/lib/apt/lists/* RUN echo "[local]\nlocalhost ansible_connection=local" > /etc/ansible/hosts From 42c1be1b24af3f84b903ddbb76cd15ca1469373e Mon Sep 17 00:00:00 2001 From: Alessandro Fael Garcia Date: Fri, 13 Apr 2018 16:11:25 -0700 Subject: [PATCH 04/11] Install curl depency in Debian based containers --- tests/dockerfiles/Dockerfile.debian-jessie | 1 + tests/dockerfiles/Dockerfile.debian-stretch | 1 + tests/dockerfiles/Dockerfile.ubuntu-trusty | 1 + tests/dockerfiles/Dockerfile.ubuntu-xenial | 1 + 4 files changed, 4 insertions(+) diff --git a/tests/dockerfiles/Dockerfile.debian-jessie b/tests/dockerfiles/Dockerfile.debian-jessie index edafeac..eafadf5 100644 --- a/tests/dockerfiles/Dockerfile.debian-jessie +++ b/tests/dockerfiles/Dockerfile.debian-jessie @@ -9,6 +9,7 @@ RUN apt-get update -y && apt-get install -y --no-install-recommends \ python-pip \ git \ apt-transport-https \ + curl \ && rm -rf /var/lib/apt/lists/* RUN pip install --upgrade setuptools && pip install ansible diff --git a/tests/dockerfiles/Dockerfile.debian-stretch b/tests/dockerfiles/Dockerfile.debian-stretch index 5cb8157..26135da 100644 --- a/tests/dockerfiles/Dockerfile.debian-stretch +++ b/tests/dockerfiles/Dockerfile.debian-stretch @@ -10,6 +10,7 @@ RUN apt-get update -y && apt-get install -y --no-install-recommends \ git \ systemd \ apt-transport-https \ + curl \ && rm -rf /var/lib/apt/lists/* RUN pip install --upgrade setuptools && pip install ansible diff --git a/tests/dockerfiles/Dockerfile.ubuntu-trusty b/tests/dockerfiles/Dockerfile.ubuntu-trusty index 4223f20..c36e55e 100644 --- a/tests/dockerfiles/Dockerfile.ubuntu-trusty +++ b/tests/dockerfiles/Dockerfile.ubuntu-trusty @@ -6,6 +6,7 @@ RUN apt-add-repository -y ppa:ansible/ansible && apt-get update && apt-get insta git \ ansible \ apt-transport-https \ + curl \ && rm -rf /var/lib/apt/lists/* RUN echo "[local]\nlocalhost ansible_connection=local" > /etc/ansible/hosts diff --git a/tests/dockerfiles/Dockerfile.ubuntu-xenial b/tests/dockerfiles/Dockerfile.ubuntu-xenial index 56b7c39..f8ad055 100644 --- a/tests/dockerfiles/Dockerfile.ubuntu-xenial +++ b/tests/dockerfiles/Dockerfile.ubuntu-xenial @@ -6,6 +6,7 @@ RUN apt-add-repository -y ppa:ansible/ansible && apt-get update && apt-get insta git \ ansible \ apt-transport-https \ + curl \ && rm -rf /var/lib/apt/lists/* RUN echo "[local]\nlocalhost ansible_connection=local" > /etc/ansible/hosts From 68f4939d0fdcba8456535310cd1b528c5ea56fb6 Mon Sep 17 00:00:00 2001 From: Alessandro Fael Garcia Date: Fri, 13 Apr 2018 16:47:07 -0700 Subject: [PATCH 05/11] Install gnupg1 dependency --- tests/dockerfiles/Dockerfile.debian-stretch | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/dockerfiles/Dockerfile.debian-stretch b/tests/dockerfiles/Dockerfile.debian-stretch index 26135da..7d924dc 100644 --- a/tests/dockerfiles/Dockerfile.debian-stretch +++ b/tests/dockerfiles/Dockerfile.debian-stretch @@ -11,6 +11,7 @@ RUN apt-get update -y && apt-get install -y --no-install-recommends \ systemd \ apt-transport-https \ curl \ + gnupg1 \ && rm -rf /var/lib/apt/lists/* RUN pip install --upgrade setuptools && pip install ansible From 408b09222cf16b22fed8d1b0c80ceb3f15be11da Mon Sep 17 00:00:00 2001 From: Alessandro Fael Garcia Date: Fri, 13 Apr 2018 16:57:39 -0700 Subject: [PATCH 06/11] Replace gnupg1 by gnupg2 --- tests/dockerfiles/Dockerfile.debian-stretch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/dockerfiles/Dockerfile.debian-stretch b/tests/dockerfiles/Dockerfile.debian-stretch index 7d924dc..3071aab 100644 --- a/tests/dockerfiles/Dockerfile.debian-stretch +++ b/tests/dockerfiles/Dockerfile.debian-stretch @@ -11,7 +11,7 @@ RUN apt-get update -y && apt-get install -y --no-install-recommends \ systemd \ apt-transport-https \ curl \ - gnupg1 \ + gnupg2 \ && rm -rf /var/lib/apt/lists/* RUN pip install --upgrade setuptools && pip install ansible From 722b99d766422c8e05ade7857a6e82819caf651a Mon Sep 17 00:00:00 2001 From: Alessandro Fael Garcia Date: Fri, 13 Apr 2018 17:10:29 -0700 Subject: [PATCH 07/11] Install dirmngr dependency --- tests/dockerfiles/Dockerfile.debian-stretch | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/dockerfiles/Dockerfile.debian-stretch b/tests/dockerfiles/Dockerfile.debian-stretch index 3071aab..1a0e1e3 100644 --- a/tests/dockerfiles/Dockerfile.debian-stretch +++ b/tests/dockerfiles/Dockerfile.debian-stretch @@ -12,6 +12,7 @@ RUN apt-get update -y && apt-get install -y --no-install-recommends \ apt-transport-https \ curl \ gnupg2 \ + dirmngr \ && rm -rf /var/lib/apt/lists/* RUN pip install --upgrade setuptools && pip install ansible From 4281c51dbc97897451d637c20b32853a12e677f5 Mon Sep 17 00:00:00 2001 From: Alessandro Fael Garcia Date: Mon, 16 Apr 2018 13:28:32 -0700 Subject: [PATCH 08/11] Create test playbooks --- .travis.yml | 10 +++-- tests/files/http/default.conf | 44 +++++++++++++++++++ tests/files/nginx.conf | 31 +++++++++++++ tests/inventory | 1 - .../nginx-opensource.yml} | 1 + tests/playbooks/nginx-template.yml | 10 +++++ tests/playbooks/nginx-upload.yml | 11 +++++ 7 files changed, 104 insertions(+), 4 deletions(-) create mode 100644 tests/files/http/default.conf create mode 100644 tests/files/nginx.conf delete mode 100644 tests/inventory rename tests/{test.yml => playbooks/nginx-opensource.yml} (83%) create mode 100644 tests/playbooks/nginx-template.yml create mode 100644 tests/playbooks/nginx-upload.yml diff --git a/.travis.yml b/.travis.yml index 0f32d06..b315d0b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,16 +15,20 @@ env: version: jessie - distribution: debian version: stretch +tests: + - opensource + - template + - upload 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: - 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/test.yml --syntax-check' - - 'sudo docker exec "$(cat ${container_id})" env ANSIBLE_FORCE_COLOR=1 ansible-playbook -v /etc/ansible/roles/ansible-role-nginx/tests/test.yml' + - 'sudo docker exec "$(cat ${container_id})" env ANSIBLE_FORCE_COLOR=1 ansible-playbook -v /etc/ansible/roles/ansible-role-nginx/tests/playbooks/nginx-${tests}.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-${tests}.yml' - > - sudo docker exec "$(cat ${container_id})" env ANSIBLE_FORCE_COLOR=1 ansible-playbook -v /etc/ansible/roles/ansible-role-nginx/tests/test.yml + sudo docker exec "$(cat ${container_id})" env ANSIBLE_FORCE_COLOR=1 ansible-playbook -v /etc/ansible/roles/ansible-role-nginx/tests/playbooks/nginx-${tests}.yml | grep -q 'changed=0.*failed=0' && (echo 'Idempotence test: pass' && exit 0) || (echo 'Idempotence test: fail' && exit 1) 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-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 diff --git a/tests/playbooks/nginx-upload.yml b/tests/playbooks/nginx-upload.yml new file mode 100644 index 0000000..66db643 --- /dev/null +++ b/tests/playbooks/nginx-upload.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: false + http_push_location: ../files/http/*.conf From 60331d7b39d7dbc98d88867a1cca4866ec16bd23 Mon Sep 17 00:00:00 2001 From: Alessandro Fael Garcia Date: Mon, 16 Apr 2018 13:46:19 -0700 Subject: [PATCH 09/11] Use global environment variable in Travis build matrix --- .travis.yml | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/.travis.yml b/.travis.yml index b315d0b..3cd14bb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,32 +3,33 @@ sudo: required services: - docker env: - - distribution: centos - version: 6 - - distribution: centos - version: 7 - - distribution: ubuntu - version: trusty - - distribution: ubuntu - version: xenial - - distribution: debian - version: jessie - - distribution: debian - version: stretch -tests: - - opensource - - template - - upload + global: + - playbook: opensource + - playbook: template + - playbook: upload + matrix: + - distribution: centos + version: 6 + - distribution: centos + version: 7 + - distribution: ubuntu + version: trusty + - distribution: ubuntu + version: xenial + - distribution: debian + version: jessie + - distribution: debian + version: stretch 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: - 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-${tests}.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-${tests}.yml' + - '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' - > - sudo docker exec "$(cat ${container_id})" env ANSIBLE_FORCE_COLOR=1 ansible-playbook -v /etc/ansible/roles/ansible-role-nginx/tests/playbooks/nginx-${tests}.yml + 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) From 1bedaa9e0c2e2bfbfd17e4c71aa55342b8a2389a Mon Sep 17 00:00:00 2001 From: Alessandro Fael Garcia Date: Mon, 16 Apr 2018 15:56:56 -0700 Subject: [PATCH 10/11] Remove global variable from Travis build matrix Global variables rewrite each other on Travis instead of creating a build matrix --- .travis.yml | 71 ++++++++++++++----- .../{nginx-upload.yml => nginx-push.yml} | 2 +- 2 files changed, 55 insertions(+), 18 deletions(-) rename tests/playbooks/{nginx-upload.yml => nginx-push.yml} (88%) diff --git a/.travis.yml b/.travis.yml index 3cd14bb..eea3856 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,23 +3,60 @@ sudo: required services: - docker env: - global: - - playbook: opensource - - playbook: template - - playbook: upload - matrix: - - distribution: centos - version: 6 - - distribution: centos - version: 7 - - distribution: ubuntu - version: trusty - - distribution: ubuntu - version: xenial - - distribution: debian - version: jessie - - distribution: debian - version: stretch + - 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: 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 + - 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 before_install: - 'sudo docker pull ${distribution}:${version}' - 'sudo docker build --no-cache --rm --file=tests/dockerfiles/Dockerfile.${distribution}-${version} --tag=${distribution}-${version}:ansible tests' diff --git a/tests/playbooks/nginx-upload.yml b/tests/playbooks/nginx-push.yml similarity index 88% rename from tests/playbooks/nginx-upload.yml rename to tests/playbooks/nginx-push.yml index 66db643..92b753b 100644 --- a/tests/playbooks/nginx-upload.yml +++ b/tests/playbooks/nginx-push.yml @@ -7,5 +7,5 @@ vars: main_push_enable: true main_push_location: ../files/nginx.conf - http_push_enable: false + http_push_enable: true http_push_location: ../files/http/*.conf From 5d291c394389d0e6546f479eebd87b5accb94638 Mon Sep 17 00:00:00 2001 From: Alessandro Fael Garcia Date: Wed, 18 Apr 2018 13:18:48 -0700 Subject: [PATCH 11/11] Refactor .travis.yml --- .travis.yml | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/.travis.yml b/.travis.yml index eea3856..9c4878b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,24 +21,6 @@ env: - distribution: centos version: 7 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 - distribution: debian version: jessie playbook: opensource @@ -57,6 +39,24 @@ env: - 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'