test(bind9): add Molecule scenario
Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
9 files changed
+185
No files matched your search
@@ -0,0 +1,17 @@
|
||||
ARG BASE_IMAGE
|
||||
FROM ${BASE_IMAGE}
|
||||
|
||||
ENV container=docker
|
||||
|
||||
RUN if command -v pacman > /dev/null; then \
|
||||
pacman --sync --refresh --noconfirm systemd systemd-sysvcompat python; \
|
||||
elif command -v apt-get > /dev/null; then \
|
||||
apt-get update && \
|
||||
DEBIAN_FRONTEND=noninteractive apt-get install --yes systemd systemd-sysv python3 python3-apt; \
|
||||
else \
|
||||
dnf install --assumeyes systemd python3 python3-libdnf5 && \
|
||||
dnf clean all; \
|
||||
fi
|
||||
|
||||
STOPSIGNAL SIGRTMIN+3
|
||||
CMD ["/sbin/init"]
|
||||
@@ -0,0 +1,4 @@
|
||||
---
|
||||
|
||||
collections:
|
||||
- name: community.docker
|
||||
@@ -0,0 +1,12 @@
|
||||
---
|
||||
|
||||
- name: Converge
|
||||
hosts: all
|
||||
vars:
|
||||
bind9_systemd_dropin: |
|
||||
[Service]
|
||||
Environment=MOLECULE_BIND9_DROPIN=present
|
||||
tasks:
|
||||
- name: Include the role bind9
|
||||
ansible.builtin.include_role:
|
||||
name: bind9
|
||||
@@ -0,0 +1,44 @@
|
||||
---
|
||||
|
||||
- name: Create
|
||||
hosts: localhost
|
||||
gather_facts: false
|
||||
tasks:
|
||||
- name: Build systemd-enabled test images
|
||||
community.docker.docker_image:
|
||||
name: "bind9-molecule-{{ item.name }}:latest"
|
||||
source: build
|
||||
build:
|
||||
path: "{{ molecule_scenario_directory }}"
|
||||
args:
|
||||
BASE_IMAGE: "{{ item.image }}"
|
||||
loop: "{{ molecule_yml.platforms }}"
|
||||
loop_control:
|
||||
label: "{{ item.name }}"
|
||||
|
||||
- name: Start a systemd container per platform
|
||||
community.docker.docker_container:
|
||||
name: "{{ item.name }}"
|
||||
image: "bind9-molecule-{{ item.name }}:latest"
|
||||
command: /sbin/init
|
||||
state: started
|
||||
privileged: true
|
||||
cgroupns_mode: host
|
||||
tmpfs:
|
||||
- /run
|
||||
- /run/lock
|
||||
volumes:
|
||||
- /sys/fs/cgroup:/sys/fs/cgroup:rw
|
||||
loop: "{{ molecule_yml.platforms }}"
|
||||
loop_control:
|
||||
label: "{{ item.name }}"
|
||||
|
||||
- name: Write the instance config
|
||||
ansible.builtin.copy:
|
||||
content: |
|
||||
{% for platform in molecule_yml.platforms %}
|
||||
- instance: {{ platform.name }}
|
||||
connection: community.docker.docker
|
||||
{% endfor %}
|
||||
dest: "{{ molecule_instance_config }}"
|
||||
mode: "0600"
|
||||
@@ -0,0 +1,27 @@
|
||||
---
|
||||
|
||||
- name: Destroy
|
||||
hosts: localhost
|
||||
gather_facts: false
|
||||
tasks:
|
||||
- name: Remove the container of every platform
|
||||
community.docker.docker_container:
|
||||
name: "{{ item.name }}"
|
||||
state: absent
|
||||
loop: "{{ molecule_yml.platforms }}"
|
||||
loop_control:
|
||||
label: "{{ item.name }}"
|
||||
|
||||
- name: Remove the test image of every platform
|
||||
community.docker.docker_image:
|
||||
name: "bind9-molecule-{{ item.name }}:latest"
|
||||
state: absent
|
||||
loop: "{{ molecule_yml.platforms }}"
|
||||
loop_control:
|
||||
label: "{{ item.name }}"
|
||||
|
||||
- name: Empty the instance config
|
||||
ansible.builtin.copy:
|
||||
content: "[]"
|
||||
dest: "{{ molecule_instance_config }}"
|
||||
mode: "0600"
|
||||
@@ -0,0 +1,36 @@
|
||||
---
|
||||
|
||||
driver:
|
||||
name: default
|
||||
options:
|
||||
managed: true
|
||||
login_cmd_template: "docker exec --interactive --tty {instance} bash"
|
||||
|
||||
platforms:
|
||||
- name: bind9-archlinux
|
||||
image: docker.io/library/archlinux:base
|
||||
- name: bind9-debian
|
||||
image: docker.io/library/debian:13
|
||||
- name: bind9-fedora
|
||||
image: registry.fedoraproject.org/fedora:43
|
||||
|
||||
provisioner:
|
||||
name: ansible
|
||||
env:
|
||||
ANSIBLE_ROLES_PATH: "${MOLECULE_PROJECT_DIRECTORY}/.."
|
||||
config_options:
|
||||
defaults:
|
||||
interpreter_python: auto_silent
|
||||
|
||||
scenario:
|
||||
test_sequence:
|
||||
- dependency
|
||||
- cleanup
|
||||
- destroy
|
||||
- syntax
|
||||
- create
|
||||
- prepare
|
||||
- converge
|
||||
- verify
|
||||
- cleanup
|
||||
- destroy
|
||||
@@ -0,0 +1,12 @@
|
||||
---
|
||||
|
||||
- name: Prepare
|
||||
hosts: all
|
||||
tasks:
|
||||
- name: Create the parent directory for DNSSEC keys
|
||||
ansible.builtin.file:
|
||||
path: /var/named
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0755"
|
||||
state: directory
|
||||
@@ -0,0 +1,4 @@
|
||||
---
|
||||
|
||||
# The role has no role dependencies, but molecule warns about the missing file.
|
||||
roles: []
|
||||
@@ -0,0 +1,29 @@
|
||||
---
|
||||
|
||||
- name: Verify
|
||||
hosts: all
|
||||
tasks:
|
||||
- name: Validate the generated BIND configuration
|
||||
ansible.builtin.command:
|
||||
argv:
|
||||
- named-checkconf
|
||||
- "{{ '/etc/bind/named.conf' if ansible_facts['os_family'] == 'Debian' else '/etc/named.conf' }}"
|
||||
changed_when: false
|
||||
|
||||
- name: Gather service states
|
||||
ansible.builtin.service_facts:
|
||||
|
||||
- name: Assert that named is active
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- ansible_facts.services['named.service'].state == 'running'
|
||||
|
||||
- name: Read the systemd drop-in
|
||||
ansible.builtin.slurp:
|
||||
src: /etc/systemd/system/named.service.d/override.conf
|
||||
register: _bind9_systemd_dropin
|
||||
|
||||
- name: Assert that the configured systemd drop-in was installed
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- "'Environment=MOLECULE_BIND9_DROPIN=present' in (_bind9_systemd_dropin.content | b64decode)"
|
||||
Reference in new issue
Block a user