added basic molecule tests

This commit is contained in:
AnsibleGuy 2023-01-06 22:27:56 +01:00
parent caf251f4a0
commit a20f48910f
5 changed files with 112 additions and 0 deletions

View File

@ -0,0 +1,14 @@
# docker build -t mantest - < ./Dockerfile.j2
# docker run -it --privileged --name mantest mantest:latest /sbin/init --tmpfs /tmp --tmpfs /run --tmpfs /run/lock
FROM debian:11-slim
ENV container docker
ENV LC_ALL C
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update \
&& apt-get install -y systemd systemd-sysv python3 sudo \
&& apt-get clean
CMD ["/sbin/init"]

10
molecule/default/Usage.md Normal file
View File

@ -0,0 +1,10 @@
# Usage
Check out the [Molecule Tutorial](https://github.com/ansibleguy/ansible_tutorial/blob/main/Molecule.md) on how to get started!
# Running
```bash
cd roles/ansibleguy.sw_zoneminder
molecule test
```

View File

@ -0,0 +1,20 @@
---
- name: Converge
hosts: all
strategy: free # speed-up; comment-out to gain clarity
vars:
apache:
sites:
test1:
domain: 'apache2.test.ansibleguy.net'
ssl:
mode: 'ca'
cert:
cn: 'Apache2'
org: 'AnsibleGuy Test'
email: 'testmaster@ansibleguy.net'
roles:
- ansibleguy.infra_apache

View File

@ -0,0 +1,49 @@
---
_references:
docker:
all: &docker_all
docker_host: 'tcp://molecule-docker.local:2375'
# docker_host: 'unix://var/run/docker.sock' # localhost
purge_networks: true
image: 'debian:11-slim'
# for docker systemd config see: https://serverfault.com/questions/1053187/systemd-fails-to-run-in-a-docker-container-when-using-cgroupv2-cgroupns-priva
dockerfile: 'Dockerfile_debian11_systemd.j2'
build_image: yes
tmpfs: ['/tmp', '/run', '/run/lock']
privileged: true
command: '/sbin/init'
dependency:
name: galaxy
driver:
name: docker
platforms:
- name: test-ag-apache-1
docker_networks:
- name: 'test-ag-apache'
ipam_config:
- subnet: '192.168.11.0/24'
gateway: '192.168.11.254'
networks:
- name: 'test-ag-apache'
ipv4_address: '192.168.11.1'
groups: [grp_tester]
<<: *docker_all
provisioner:
name: ansible
verifier:
name: ansible
scenario:
name: default
test_sequence:
- lint
- destroy
- syntax
- create
- converge
- verify
- idempotence
- check
- destroy

View File

@ -0,0 +1,19 @@
---
- name: Verify
hosts: all
gather_facts: false
tasks:
- name: Checking that service is running and enabled
ansible.builtin.systemd:
name: 'apache2.service'
enabled: true
state: started
check_mode: true
register: svc_test
failed_when: svc_test.changed
- name: Checking that service survives restart
ansible.builtin.systemd:
name: 'apache2.service'
state: restarted