Skip to content

Commit

Permalink
Add new repository files
Browse files Browse the repository at this point in the history
  • Loading branch information
cytopia committed Nov 7, 2018
1 parent 8f17358 commit 5f17145
Show file tree
Hide file tree
Showing 8 changed files with 343 additions and 96 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

# Add repo specific stuff here...
validate.sh
.vagrant

######################################
# GENERIC
Expand Down
46 changes: 15 additions & 31 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,24 @@ services:
env:
matrix:
###
### Debian stretch
### Generic profile
###
# All roles (playbook order)
- single=0 random=0 dist=debian-stretch
- single=0 random=0 dist=generic-all
# All roles (random order)
- single=0 random=1 dist=debian-stretch
- single=0 random=1 dist=generic-all
# Start each role separately
- single=1 random=0 dist=debian-stretch
- single=1 random=0 dist=generic-all

###
### Debian testing
### Cytopia's profile
###
# All roles (playbook order)
- single=0 random=0 dist=debian-testing
- single=0 random=0 dist=cytopia-t470p
# All roles (random order)
- single=0 random=1 dist=debian-testing
- single=0 random=1 dist=cytopia-t470p
# Start each role separately
- single=1 random=0 dist=debian-testing

###
### Cytopia's profile: stretch
###
# All roles (playbook order)
- single=0 random=0 dist=cytopia-stretch
# All roles (random order)
- single=0 random=1 dist=cytopia-stretch
# Start each role separately
- single=1 random=0 dist=cytopia-stretch

###
### Cytopia's profile: testing
###
# All roles (playbook order)
- single=0 random=0 dist=cytopia-testing
# All roles (random order)
- single=0 random=1 dist=cytopia-testing
# Start each role separately
- single=1 random=0 dist=cytopia-testing
- single=1 random=0 dist=cytopia-t470p


before_script:
Expand All @@ -56,14 +36,14 @@ before_script:
script:
# 1. Run it multiple times until it succeeds. This is to prevent errors that occur due to network timeouts between travis-ci
# 2. Separate between single runs and full runs
- if [ "${single}" = "1" ]; then
- if [ "${single}" -eq "1" ]; then
ROLES="$( for d in $(/bin/ls roles/); do if [ -d roles/${d} ]; then echo $d; fi done | grep -vE '*-meta$' | sort -R )";
TOTAL="$( echo "${ROLES}" | wc -l )";
START=1;
for r in ${ROLES}; do
printf "========== Run %s / %s (%s) ==========\n" "${START}" "${TOTAL}" "${r}";
max=10; i=0; while [ $i -lt $max ]; do
if docker run --rm -e MY_HOST=${dist} -e tag=${r} -t ansible-debian; then
if make test-docker-single PROFILE=${dist} ROLE=${r}; then
break;
else
i=$((i+1));
Expand All @@ -73,5 +53,9 @@ script:
START=$((START+1));
done;
else
docker run --rm -e MY_HOST=${dist} -e random=${random} -t ansible-debian;
if [ "${random}" -eq "1" ]; then
make test-docker-random PROFILE=${dist};
else
make test-docker-full PROFILE=${dist};
fi
fi
12 changes: 6 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
FROM debian:stretch
MAINTAINER "cytopia" <[email protected]>

RUN set -x \
RUN set -eux \
&& apt-get update \
&& apt-get install --no-install-recommends --no-install-suggests -y \
python-apt \
Expand All @@ -14,18 +14,18 @@ RUN set -x \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get purge -y --autoremove

RUN set -x \
RUN set -eux \
&& pip install wheel \
&& pip install ansible

# Add user with password-less sudo
RUN set -x \
RUN set -eux \
&& useradd -m -s /bin/bash cytopia \
&& echo "cytopia ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers.d/cytopia

# Copy files
COPY ./ /home/cytopia/ansible
RUN set -x \
RUN set -eux \
&& chown -R cytopia:cytopia /home/cytopia/ansible

# Switch to user
Expand All @@ -35,12 +35,12 @@ USER cytopia
WORKDIR /home/cytopia/ansible

# Systemd cannot be checked inside Docker, so replace it with a dummy role
RUN set -x \
RUN set -eux \
&& mkdir roles/dummy \
&& sed -i'' 's/systemd-meta/dummy/g' playbook.yml

# Randomize roles to install each time the container is build (each travis run)
RUN set -x \
RUN set -eux \
&& ROLES_INSTALL="$( for d in $(/bin/ls roles/); do if [ -d roles/${d} ]; then echo $d; fi done | grep -vE '*-meta$' | sort -R )" \
&& ROLES_REMOVE="$( for d in $(/bin/ls roles/); do if [ -d roles/${d} ]; then echo $d; fi done | grep -vE '*-meta$' | sort -R )" \
\
Expand Down
Empty file modified LICENSE.md
100755 → 100644
Empty file.
113 changes: 113 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
DIR = .
FILE = Dockerfile
IMAGE = cytopia/ansible-debian
TAG = latest

# Ansible variables
VERBOSE=
PROFILE=cytopia-t470p

.PHONY: help build-docker test-docker-full test-docker-random test-docker-single itest-docker-full itest-docker-random itest-docker-single


#--------------------------------------------------------------------------------------------------
# Default Target
#--------------------------------------------------------------------------------------------------

help:
@echo "################################################################################"
@echo "# #"
@echo "# Debian Provisioning with Ansible #"
@echo "# #"
@echo "################################################################################"
@echo
@echo
@echo "------------------------------------------------------------"
@echo " Run tests in Docker"
@echo "------------------------------------------------------------"
@echo
@echo "build-docker Build the testing Docker image (happens automatically during tests)"
@echo
@echo "test-docker-docker-full Run a full test in a Docker (requires PROFILE)"
@echo "test-docker-docker-random Run a full randomized test in a Docker (requires PROFILE)"
@echo "test-docker-docker-single Run the test on a single role in a Docker (requires PROFILE and ROLE)"
@echo
@echo "itest-docker-docker-full Interactive version of test-docker-full (requires PROFILE)"
@echo "itest-docker-docker-random Interactive version of test-docker-random (requires PROFILE)"
@echo "itest-docker-docker-single Interactive version of test-docker-single (requires PROFILE and ROLE)"
@echo
@echo
@echo "------------------------------------------------------------"
@echo " Run tests in Vagrant"
@echo "------------------------------------------------------------"
@echo
@echo "------------------------------------------------------------"
@echo " Deploy your host system"
@echo "------------------------------------------------------------"
@echo


#--------------------------------------------------------------------------------------------------
# Tests with Docker
#--------------------------------------------------------------------------------------------------

build-docker:
docker build -t $(IMAGE) -f $(DIR)/$(FILE) $(DIR)

# Automated tests
test-docker-full: build-docker
docker run --rm -e MY_HOST=$(PROFILE) -e verbose=$(VERBOSE) -t $(IMAGE)

test-docker-random: build-docker
docker run --rm -e MY_HOST=$(PROFILE) -e verbose=$(VERBOSE) -e random=1 -t $(IMAGE)

test-docker-single: build-docker
docker run --rm -e MY_HOST=$(PROFILE) -e verbose=$(VERBOSE) -e tag=$(ROLE) -t $(IMAGE)

# Interactive tests
# When inside the Container execute: ./run-tests.sh
itest-docker-full: build-docker
docker run -it --rm --entrypoint=bash -e MY_HOST=$(PROFILE) -e verbose=$(VERBOSE) -t $(IMAGE)

itest-docker-random: build-docker
docker run -it --rm --entrypoint=bash -e MY_HOST=$(PROFILE) -e verbose=$(VERBOSE) -e random=1 -t $(IMAGE)

itest-docker-single: build-docker
docker run -it --rm --entrypoint=bash -e MY_HOST=$(PROFILE) -e verbose=$(VERBOSE) -e tag=$(ROLE) -t $(IMAGE)


#--------------------------------------------------------------------------------------------------
# Tests with Vagrant
#--------------------------------------------------------------------------------------------------

# Test your profile with Vagrant
test-vagrant:
vagrant rsync
PROFILE=$(PROFILE) vagrant up --provision


#--------------------------------------------------------------------------------------------------
# Deploy Targets
#--------------------------------------------------------------------------------------------------

# (Step 1/3) Ensure required software is present
deploy-init:
DEBIAN_FRONTEND=noninteractive apt-get update -qq
DEBIAN_FRONTEND=noninteractive apt-get install -qq -q --no-install-recommends --no-install-suggests \
python-apt \
python-dev \
python-jmespath \
python-pip \
python-setuptools
pip install wheel
pip install ansible

# (Step 2/3) Add new Debian sources and dist-upgrade your system
deploy-dist-upgrade:
ansible-playbook -i inventory playbook.yml --limit ${PROFILE} --diff -t bootstrap-system --ask-become-pass
DEBIAN_FRONTEND=noninteractive apt-get update -qq
DEBIAN_FRONTEND=noninteractive apt-get dist-upgrade -qq -y

# (Step 3/3) Deploy your system
deploy-tools:
ansible-playbook -i inventory playbook.yml --limit ${PROFILE} --diff --ask-become-pass
Loading

0 comments on commit 5f17145

Please sign in to comment.