Skip to content
Snippets Groups Projects
Commit fa0f39e7 authored by Jörg Sachse's avatar Jörg Sachse
Browse files

feat: add local Docker-based test suite

parent 5316a468
No related branches found
No related tags found
No related merge requests found
FROM debian:stable-slim
### configure SLUB Debian Repository
RUN apt-get update; \
apt-get install -y --no-install-recommends gnupg wget git; \
wget -O - http://sdvdebianrepo.slub-dresden.de/deb-repository/pub.gpg.key | apt-key add - ; \
echo "deb http://sdvdebianrepo.slub-dresden.de/deb-repository bullseye main" > /etc/apt/sources.list.d/slub.list;
RUN apt-get update && apt-get install -y --no-install-recommends openssh-server sudo python3 unzip
RUN mkdir /var/run/sshd
RUN echo 'root:root' | chpasswd
RUN sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
# SSH login fix. Otherwise user is kicked off after login
RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd
ENV NOTVISIBLE "in users profile"
RUN echo "export VISIBLE=now" >> /etc/profile
RUN groupadd lza
EXPOSE 22
CMD ["/usr/sbin/sshd", "-D"]
You want to run the Ansible role against a local Docker container to see if it works as expected? Just run:
```bash
./docker-run-test.sh
```
It will build a Docker image from the `Dockerfile` based on debian:stable-slim, spin up a container, run the Ansible tasks against it using the tasks in `docker-playbook.yml` and the hosts from the inventory `docker-inventory.ini`, and remove the Container if everything went smoothly.
Special thanks to Ayesha M., who wrote the article that this test suite is based on (https://ayeshasilvia.medium.com/testing-ansible-playbook-in-a-docker-container-21628e9ee256).
[local]
lza-repair-test python_interpreter=python3
---
- hosts: "local"
connection: docker
# Collect facts from remote system? Possible values: true, false
gather_facts: true
# any_error_fatal will mark all the hosts as failed if fails and immediately abort the playbook execution. Possible values: true, false
any_errors_fatal: false
# max_fail_percentage allows you to abort the play if certain threshold of failures have been reached.
max_fail_percentage: 30
serial: 30
# hide sensitive information in verbose/debugging output from others. Possible values: true, false
no_log: false
# execution strategy, possible values: debug, linear, serial, free (https://docs.ansible.com/ansible/latest/user_guide/playbooks_strategies.html)
strategy: linear
roles:
- { role: ansible_lza_repair, become: true }
#!/usr/bin/env bash
RED="\\e[31m"
WHITE="\\e[0m"
ERROR="${RED}[ERROR]\t${WHITE}"
DOCKER_CONTAINER_NAME="lza-repair-test"
REQUIREMENTS="docker ansible-playbook"
export ANSIBLE_NOCOWS=true
export ANSIBLE_ROLES_PATH=../
for REQUIREMENT in ${REQUIREMENTS}; do
command -v "${REQUIREMENT}" >/dev/null 2>&1 || { echo >&2 "${ERROR}${REQUIREMENT} required but not installed. Aborting."; exit 1; }
done
cd ../../
docker build -t ${DOCKER_CONTAINER_NAME} tests/
docker run -it --name ${DOCKER_CONTAINER_NAME} -d -p 5000:22 ${DOCKER_CONTAINER_NAME}
pwd
ansible-playbook --inventory "tests/local/docker-inventory.ini" --user "root" --tags ci "tests/local/docker-playbook.yml"
docker stop ${DOCKER_CONTAINER_NAME}
docker rm ${DOCKER_CONTAINER_NAME}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment