Skip to content

Commit 2b72889

Browse files
committed
Test role across multiple distributions
Implement support to test the role in multiple Linux distributions by deploying Docker containers within Travis
1 parent ae27bdc commit 2b72889

File tree

7 files changed

+123
-24
lines changed

7 files changed

+123
-24
lines changed

.travis.yml

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,34 @@
11
---
2-
language: python
3-
python: "2.7"
4-
# Use the new container infrastructure
52
sudo: required
6-
# Install ansible
7-
addons:
8-
apt:
9-
packages:
10-
- python-pip
11-
install:
12-
# Install ansible
13-
- pip install ansible
14-
# Check ansible version
15-
- ansible --version
16-
# Create ansible.cfg with correct roles_path
17-
- printf '[defaults]\nroles_path=../' >ansible.cfg
3+
services:
4+
- docker
5+
env:
6+
- distribution: centos
7+
version: 6
8+
- distribution: centos
9+
version: 7
10+
- distribution: ubuntu
11+
version: trusty
12+
- distribution: ubuntu
13+
version: xenial
14+
- distribution: debian
15+
version: jessie
16+
- distribution: debian
17+
version: stretch
18+
before_install:
19+
- 'sudo docker pull ${distribution}:${version}'
20+
- 'sudo docker build --no-cache --rm --file=tests/dockerfiles/Dockerfile.${distribution}-${version} --tag=${distribution}-${version}:ansible tests'
1821
script:
19-
# Basic role syntax check
20-
- ansible-playbook tests/test.yml -i tests/inventory --syntax-check
21-
# Run the role with ansible-playbook.
22-
- ansible-playbook tests/test.yml -i tests/inventory --connection=local --become
23-
# Run the role again, checking to make sure it's idempotent.
22+
- container_id=$(mktemp)
23+
- '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}"'
24+
- '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'
25+
- 'sudo docker exec "$(cat ${container_id})" env ANSIBLE_FORCE_COLOR=1 ansible-playbook -v /etc/ansible/roles/ansible-role-nginx/tests/test.yml'
2426
- >
25-
ansible-playbook tests/test.yml -i tests/inventory --connection=local --become | grep -q 'changed=0.*failed=0'
26-
&& (echo 'Idempotence test: pass' && exit 0) || (echo 'Idempotence test: fail' && exit 1)
27-
# Request a page via the web server, to make sure NGINX is running and responds.
28-
- curl http://localhost/
27+
sudo docker exec "$(cat ${container_id})" env ANSIBLE_FORCE_COLOR=1 ansible-playbook -v /etc/ansible/roles/ansible-role-nginx/tests/test.yml
28+
| grep -q 'changed=0.*failed=0'
29+
&& (echo 'Idempotence test: pass' && exit 0)
30+
|| (echo 'Idempotence test: fail' && exit 1)
31+
- 'sudo docker exec "$(cat ${container_id})" curl http://localhost/'
32+
- 'sudo docker rm -f "$(cat ${container_id})"'
2933
notifications:
3034
webhooks: https://galaxy.ansible.com/api/v1/notifications/

tests/dockerfiles/Dockerfile.centos-6

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM centos:6
2+
3+
RUN yum -y install epel-release
4+
RUN yum -y install git ansible sudo
5+
6+
RUN sed -i -e 's/^\(Defaults\s*requiretty\)/#--- \1/' /etc/sudoers
7+
8+
RUN echo -e '[local]\nlocalhost ansible_connection=local' > /etc/ansible/hosts
9+
10+
VOLUME ["/sys/fs/cgroup"]
11+
12+
CMD ["/usr/sbin/init"]

tests/dockerfiles/Dockerfile.centos-7

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
FROM centos:7
2+
3+
# Install systemd -- See https://hub.docker.com/_/centos/
4+
RUN yum -y swap -- remove fakesystemd -- install systemd systemd-libs
5+
RUN yum -y update; \
6+
(cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == systemd-tmpfiles-setup.service ] || rm -f $i; done); \
7+
rm -f /lib/systemd/system/multi-user.target.wants/*; \
8+
rm -f /etc/systemd/system/*.wants/*; \
9+
rm -f /lib/systemd/system/local-fs.target.wants/*; \
10+
rm -f /lib/systemd/system/sockets.target.wants/*udev*; \
11+
rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \
12+
rm -f /lib/systemd/system/basic.target.wants/*; \
13+
rm -f /lib/systemd/system/anaconda.target.wants/*;
14+
15+
RUN yum -y install epel-release
16+
RUN yum -y install git ansible sudo
17+
18+
RUN sed -i -e 's/^\(Defaults\s*requiretty\)/#--- \1/' /etc/sudoers
19+
20+
RUN echo -e '[local]\nlocalhost ansible_connection=local' > /etc/ansible/hosts
21+
22+
VOLUME ["/sys/fs/cgroup"]
23+
24+
CMD ["/usr/sbin/init"]
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
FROM debian:jessie
2+
3+
RUN apt-get update -y && apt-get install -y --no-install-recommends \
4+
software-properties-common \
5+
build-essential \
6+
libffi-dev \
7+
libssl-dev \
8+
python-dev \
9+
python-pip \
10+
git \
11+
&& rm -rf /var/lib/apt/lists/*
12+
13+
RUN pip install --upgrade setuptools && pip install ansible
14+
15+
RUN mkdir -p /etc/ansible && echo "[local]\nlocalhost ansible_connection=local" > /etc/ansible/hosts
16+
17+
ENTRYPOINT ["/sbin/init"]
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
FROM debian:stretch
2+
3+
RUN apt-get update -y && apt-get install -y --no-install-recommends \
4+
software-properties-common \
5+
build-essential \
6+
libffi-dev \
7+
libssl-dev \
8+
python-dev \
9+
python-pip \
10+
git \
11+
systemd \
12+
&& rm -rf /var/lib/apt/lists/*
13+
14+
RUN pip install --upgrade setuptools && pip install ansible
15+
16+
RUN mkdir -p /etc/ansible && echo "[local]\nlocalhost ansible_connection=local" > /etc/ansible/hosts
17+
18+
ENTRYPOINT ["/bin/systemd"]
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM ubuntu:trusty
2+
3+
RUN apt-get update && apt-get dist-upgrade -y && apt-get install -y software-properties-common && rm -rf /var/lib/apt/lists/*
4+
5+
RUN apt-add-repository -y ppa:ansible/ansible && apt-get update && apt-get install -y \
6+
git \
7+
ansible \
8+
&& rm -rf /var/lib/apt/lists/*
9+
10+
RUN echo "[local]\nlocalhost ansible_connection=local" > /etc/ansible/hosts
11+
12+
ENTRYPOINT ["/sbin/init"]
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM ubuntu:xenial
2+
3+
RUN apt-get update && apt-get dist-upgrade -y && apt-get install -y software-properties-common && rm -rf /var/lib/apt/lists/*
4+
5+
RUN apt-add-repository -y ppa:ansible/ansible && apt-get update && apt-get install -y \
6+
git \
7+
ansible \
8+
&& rm -rf /var/lib/apt/lists/*
9+
10+
RUN echo "[local]\nlocalhost ansible_connection=local" > /etc/ansible/hosts
11+
12+
ENTRYPOINT ["/sbin/init"]

0 commit comments

Comments
 (0)