Test role across multiple distributions

Implement support to test the role in multiple Linux distributions by deploying Docker containers within Travis
This commit is contained in:
Alessandro Fael Garcia 2018-04-13 15:24:09 -07:00
parent ae27bdcbed
commit 2b72889d90
7 changed files with 123 additions and 24 deletions

View File

@ -1,30 +1,34 @@
--- ---
language: python
python: "2.7"
# Use the new container infrastructure
sudo: required sudo: required
# Install ansible services:
addons: - docker
apt: env:
packages: - distribution: centos
- python-pip version: 6
install: - distribution: centos
# Install ansible version: 7
- pip install ansible - distribution: ubuntu
# Check ansible version version: trusty
- ansible --version - distribution: ubuntu
# Create ansible.cfg with correct roles_path version: xenial
- printf '[defaults]\nroles_path=../' >ansible.cfg - 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: script:
# Basic role syntax check - container_id=$(mktemp)
- ansible-playbook tests/test.yml -i tests/inventory --syntax-check - '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}"'
# Run the role with ansible-playbook. - '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'
- ansible-playbook tests/test.yml -i tests/inventory --connection=local --become - 'sudo docker exec "$(cat ${container_id})" env ANSIBLE_FORCE_COLOR=1 ansible-playbook -v /etc/ansible/roles/ansible-role-nginx/tests/test.yml'
# Run the role again, checking to make sure it's idempotent.
- > - >
ansible-playbook tests/test.yml -i tests/inventory --connection=local --become | grep -q 'changed=0.*failed=0' sudo docker exec "$(cat ${container_id})" env ANSIBLE_FORCE_COLOR=1 ansible-playbook -v /etc/ansible/roles/ansible-role-nginx/tests/test.yml
&& (echo 'Idempotence test: pass' && exit 0) || (echo 'Idempotence test: fail' && exit 1) | grep -q 'changed=0.*failed=0'
# Request a page via the web server, to make sure NGINX is running and responds. && (echo 'Idempotence test: pass' && exit 0)
- curl http://localhost/ || (echo 'Idempotence test: fail' && exit 1)
- 'sudo docker exec "$(cat ${container_id})" curl http://localhost/'
- 'sudo docker rm -f "$(cat ${container_id})"'
notifications: notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/ webhooks: https://galaxy.ansible.com/api/v1/notifications/

View File

@ -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"]

View File

@ -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"]

View File

@ -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"]

View File

@ -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"]

View File

@ -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"]

View File

@ -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"]