summaryrefslogtreecommitdiffstats
path: root/molecule
diff options
context:
space:
mode:
Diffstat (limited to 'molecule')
-rw-r--r--molecule/default/Dockerfile.archlinux.j220
-rw-r--r--molecule/default/Dockerfile.debian.j221
-rw-r--r--molecule/default/Dockerfile.ubuntu.j227
-rw-r--r--molecule/default/cleanup.yml9
-rw-r--r--molecule/default/converge.yml44
-rw-r--r--molecule/default/molecule.yml55
-rw-r--r--molecule/default/prepare.yml31
7 files changed, 207 insertions, 0 deletions
diff --git a/molecule/default/Dockerfile.archlinux.j2 b/molecule/default/Dockerfile.archlinux.j2
new file mode 100644
index 0000000..9b2cbd8
--- /dev/null
+++ b/molecule/default/Dockerfile.archlinux.j2
@@ -0,0 +1,20 @@
+FROM --platform=linux/amd64 docker.io/library/archlinux
+
+ENV container docker
+
+RUN pacman -Syu --noconfirm --needed python3 parted dosfstools arch-install-scripts \
+ && pacman -Scc --noconfirm
+
+RUN (cd /lib/systemd/system/sysinit.target.wants/; \
+ for i in *; do [ $i == systemd-tmpfiles-setup.service ] || rm -f $i; done); \
+ rm -f /lib/systemd/system/multi-user.target.wants/*;\
+ rm -f /etc/systemd/system/*.wants/*;\
+ rm -f /lib/systemd/system/local-fs.target.wants/*; \
+ rm -f /lib/systemd/system/sockets.target.wants/*udev*; \
+ rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \
+ rm -f /lib/systemd/system/basic.target.wants/*;\
+ rm -f /lib/systemd/system/anaconda.target.wants/*;
+
+VOLUME ["/sys/fs/cgroup"]
+
+CMD ["/usr/sbin/init"]
diff --git a/molecule/default/Dockerfile.debian.j2 b/molecule/default/Dockerfile.debian.j2
new file mode 100644
index 0000000..c28918e
--- /dev/null
+++ b/molecule/default/Dockerfile.debian.j2
@@ -0,0 +1,21 @@
+# Based on the amazing work of geerlingguy <3
+# FROM docker.io/geerlingguy/docker-debian12-ansible
+FROM docker.io/library/debian:bookworm
+
+ARG DEBIAN_FRONTEND=noninteractive
+
+ENV container docker
+
+RUN apt-get update \
+ && apt-get install -y --no-install-recommends \
+ systemd systemd-sysv python3 parted dosfstools \
+ && rm -Rf /var/lib/apt/lists/* \
+ && rm -Rf /usr/share/doc \
+ && rm -Rf /usr/share/man \
+ && apt-get clean
+
+RUN rm -f /lib/systemd/system/multi-user.target.wants/getty.target
+
+VOLUME ["/sys/fs/cgroup", "/tmp", "/run", "/opt"]
+
+CMD ["/lib/systemd/systemd"]
diff --git a/molecule/default/Dockerfile.ubuntu.j2 b/molecule/default/Dockerfile.ubuntu.j2
new file mode 100644
index 0000000..63ceca0
--- /dev/null
+++ b/molecule/default/Dockerfile.ubuntu.j2
@@ -0,0 +1,27 @@
+# Based on the amazing work of geerlingguy <3
+# FROM docker.io/geerlingguy/docker-ubuntu2404-ansible
+FROM docker.io/library/ubuntu:noble
+
+ARG DEBIAN_FRONTEND=noninteractive
+
+ENV container docker
+
+RUN apt-get update \
+ && apt-get install -y --no-install-recommends \
+ locales systemd python3 parted dosfstools \
+ && apt-get clean \
+ && rm -Rf /var/lib/apt/lists/* \
+ && rm -Rf /usr/share/doc \
+ && rm -Rf /usr/share/man
+
+# Fix potential UTF-8 errors with ansible-test.
+RUN locale-gen en_US.UTF-8
+
+# Remove unnecessary getty and udev targets that result in high CPU usage when using
+# multiple containers with Molecule (https://github.com/ansible/molecule/issues/1104)
+RUN rm -f /lib/systemd/system/systemd*udev* \
+ && rm -f /lib/systemd/system/getty.target
+
+VOLUME ["/sys/fs/cgroup", "/tmp", "/run", "/opt"]
+
+CMD ["/lib/systemd/systemd"]
diff --git a/molecule/default/cleanup.yml b/molecule/default/cleanup.yml
new file mode 100644
index 0000000..9540c83
--- /dev/null
+++ b/molecule/default/cleanup.yml
@@ -0,0 +1,9 @@
+---
+- name: Cleanup
+ hosts: localhost
+ tasks:
+ - name: "Remove testing loop device"
+ become: true
+ ansible.builtin.command:
+ cmd: "losetup -D"
+ changed_when: false
diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml
new file mode 100644
index 0000000..0a26ebd
--- /dev/null
+++ b/molecule/default/converge.yml
@@ -0,0 +1,44 @@
+---
+- name: Converge
+ hosts: instance
+ gather_facts: true
+ vars:
+ partition_wipe: false
+ partition_disk: "{{ test_device }}"
+ partition_boot:
+ num: 1
+ name: "boot"
+ flags: [boot, esp]
+ part_start: "0%"
+ part_end: "1.0GiB"
+ fstype: "vfat"
+ fstype_opts: "-F 32"
+ dev: "{{ partition_disk }}p1"
+ mount_path: "/mnt/boot"
+ fstab_opts: "defaults,nodev,nosuid,noexec,umask=0077"
+ partition_swap:
+ num: 2
+ name: "swap"
+ flags: [swap]
+ part_start: "1.0GiB"
+ part_end: "2.0GiB"
+ fstype: "ext4"
+ dev: "{{ partition_disk }}p2"
+ mount_path: "none"
+ partition_root:
+ num: 3
+ name: "root"
+ part_start: "2.0GiB"
+ part_end: "100%"
+ fstype: "ext4"
+ dev: "{{ partition_disk }}p3"
+ mount_path: "/mnt"
+ partition_extras: []
+
+ pre_tasks:
+ - name: "Get test facts"
+ ansible.builtin.set_fact:
+ test_device: "{{ hostvars['localhost']['test_device'] }}"
+
+ roles:
+ - role: partition
diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml
new file mode 100644
index 0000000..a5b30f5
--- /dev/null
+++ b/molecule/default/molecule.yml
@@ -0,0 +1,55 @@
+---
+role_name_check: 1
+dependency:
+ name: galaxy
+ options:
+ ignore-errors: true
+driver:
+ name: docker
+platforms:
+ - name: instance
+ image: ${MOLECULE_DISTRO:-archlinux}
+ dockerfile: Dockerfile.${MOLECULE_DISTRO:-archlinux}.j2
+ pre_build_image: false
+ privileged: true
+ command: ${MOLECULE_COMMAND:-""}
+ tmpfs:
+ - "/tmp"
+ - "/run"
+ - "/opt"
+ volumes:
+ - "/sys/fs/cgroup:/sys/fs/cgroup:rw"
+ - "/dev:/dev:rw"
+ cgroupns_mode: host
+provisioner:
+ name: ansible
+ inventory:
+ links:
+ host_vars: "../../host_vars/"
+ env:
+ MOLECULE_DISTRO: "${MOLECULE_DISTRO:-archlinux}"
+ ANSIBLE_ROLES_PATH: "../../roles"
+ config_options:
+ defaults:
+ fact_caching: jsonfile
+ fact_caching_connection: /tmp/facts_cache
+ fact_caching_timeout: 600
+ callback_result_format: yaml
+ interpreter_python: /usr/bin/python3
+ ssh_connection:
+ pipelining: true
+ playbooks:
+ converge: converge.yml
+verifier:
+ name: ansible
+
+# disable idempotency test for this playbook as it is not idempotent in nature
+scenario:
+ test_sequence:
+ - destroy
+ - syntax
+ - create
+ - prepare
+ - converge
+ - verify
+ - destroy
diff --git a/molecule/default/prepare.yml b/molecule/default/prepare.yml
new file mode 100644
index 0000000..b9f84a7
--- /dev/null
+++ b/molecule/default/prepare.yml
@@ -0,0 +1,31 @@
+---
+- name: Prepare
+ hosts: localhost
+ gather_facts: true
+ tasks:
+ - name: "Create virtual disk image"
+ become: true
+ community.general.filesize:
+ path: "/opt/vdd.img"
+ size: 12G
+ mode: "0755"
+ force: true
+
+ - name: "Create test_device (loop block device)"
+ become: true
+ ansible.builtin.command:
+ cmd: "losetup --show -Pf /opt/vdd.img"
+ register: loop_device
+ changed_when: true
+
+ - name: "Set test facts"
+ ansible.builtin.set_fact:
+ test_device: "{{ loop_device.stdout }}"
+ cacheable: true
+
+ - name: "Show test info"
+ ansible.builtin.debug:
+ msg: "{{ item.name }}: {{ item.value }}"
+ with_items:
+ - name: "Test Device"
+ value: "{{ test_device }}"