From eb732abaded8ef5419752380425e941117e2ddb2 Mon Sep 17 00:00:00 2001 From: Darshaka Pathirana Date: Sun, 25 Sep 2022 23:20:10 +0200 Subject: [PATCH] Update default molecule scenario Using geerlingguy/docker-debian10-ansible + geerlingguy/docker-debian11-ansible in Ansible molecule currently do not work with systemd, see: geerlingguy/docker-debian11-ansible#4. Instead, took Dockfiles from @aussielunix (Thx!) found here (but removed 'Australia/Sydney' timezone): * https://gitlab.com/aussielunix/ansible/molecule-containers/-/blob/main/debian/buster/Dockerfile * https://gitlab.com/aussielunix/ansible/molecule-containers/-/blob/main/debian/bullseye/Dockerfile Compare with @geerlingguy's current Dockerfiles: * https://github.com/geerlingguy/docker-debian10-ansible/blob/6f6a1650421afc953eb11439db9e5dabcc4d3afe/Dockerfile * https://github.com/geerlingguy/docker-debian11-ansible/blob/101602c7b9e7b3e100b7435eaa455b94189b2d47/Dockerfile Note, that when using `dockerfile`, `image` seems to be needed too. Used `docker.io/debian:$DISTRIBUTION-slim` for `image` as they are the base images for @aussielunix's Dockerfiles. I could have used @aussielinux gitlab container registry as `image`, but currently 'debian:bullseye' is missing: * https://gitlab.com/aussielunix/ansible/molecule-containers/container_registry/3343441 See: https://github.com/geerlingguy/docker-debian11-ansible/issues/4#issuecomment-1225082481 --- .../default/Dockerfile_debian_bullseye.j2 | 48 +++++++++++++++++++ molecule/default/Dockerfile_debian_buster.j2 | 48 +++++++++++++++++++ molecule/default/molecule.yml | 24 ++++++---- 3 files changed, 110 insertions(+), 10 deletions(-) create mode 100644 molecule/default/Dockerfile_debian_bullseye.j2 create mode 100644 molecule/default/Dockerfile_debian_buster.j2 diff --git a/molecule/default/Dockerfile_debian_bullseye.j2 b/molecule/default/Dockerfile_debian_bullseye.j2 new file mode 100644 index 0000000..8704704 --- /dev/null +++ b/molecule/default/Dockerfile_debian_bullseye.j2 @@ -0,0 +1,48 @@ +FROM docker.io/debian:bullseye-slim + +LABEL org.opencontainers.image.description="Debian 11 Container for Molecule" +LABEL org.opencontainers.image.source=https://gitlab.com/aussielunix/ansible/molecule-containers + +ENV LC_ALL en_US.UTF-8 +ENV LANG en_US.UTF-8 +ENV LANGUAGE en_US.UTF-8 + +# Avoid apt warnings by switching to noninteractive +ENV DEBIAN_FRONTEND=noninteractive + +# Configure apt and install packages +RUN apt-get update \ + && apt-get -y install --no-install-recommends systemd systemd-sysv \ + sudo procps python3-pip python3-dev python3-setuptools python3-wheel \ + # Clean up + && rm -rf /var/lib/apt/lists/* \ + && rm -Rf /usr/share/doc && rm -Rf /usr/share/man \ + && apt-get clean + +# Create `ansible` user and group with sudo permissions +RUN set -xe \ + && useradd -m -U -G sudo -s /bin/bash ansible \ + && sed -i "/^%sudo/s/ALL\$/NOPASSWD:ALL/g" /etc/sudoers + +# Upgrade pip to latest version to avoid wheel / cryptography issues +RUN pip3 install --upgrade pip + +# Install Ansible via pip. +RUN pip3 install ansible-core ansible-lint cryptography + +# Install Ansible inventory file. +RUN mkdir -p /etc/ansible +RUN echo "[local]\nlocalhost ansible_connection=local" > /etc/ansible/hosts + +# Switch back to dialog for any ad-hoc use of apt-get +ENV DEBIAN_FRONTEND=dialog + +RUN rm -f /lib/systemd/system/multi-user.target.wants/* \ + /etc/systemd/system/*.wants/* \ + /lib/systemd/system/local-fs.target.wants/* \ + /lib/systemd/system/sockets.target.wants/*udev* \ + /lib/systemd/system/sockets.target.wants/*initctl* \ + /lib/systemd/system/sysinit.target.wants/systemd-tmpfiles-setup* \ + /lib/systemd/system/systemd-update-utmp* + +CMD [ "/lib/systemd/systemd", "log-level=info", "unit=sysinit.target" ] diff --git a/molecule/default/Dockerfile_debian_buster.j2 b/molecule/default/Dockerfile_debian_buster.j2 new file mode 100644 index 0000000..0ba9e2d --- /dev/null +++ b/molecule/default/Dockerfile_debian_buster.j2 @@ -0,0 +1,48 @@ +FROM docker.io/debian:buster-slim + +LABEL org.opencontainers.image.description="Debian 10 Container for Molecule" +LABEL org.opencontainers.image.source=https://gitlab.com/aussielunix/ansible/molecule-containers + +ENV LC_ALL en_US.UTF-8 +ENV LANG en_US.UTF-8 +ENV LANGUAGE en_US.UTF-8 + +# Avoid apt warnings by switching to noninteractive +ENV DEBIAN_FRONTEND=noninteractive + +# Configure apt and install packages +RUN apt-get update \ + && apt-get -y install --no-install-recommends systemd systemd-sysv \ + sudo procps python3-pip python3-dev python3-setuptools python3-wheel \ + # Clean up + && rm -rf /var/lib/apt/lists/* \ + && rm -Rf /usr/share/doc && rm -Rf /usr/share/man \ + && apt-get clean + +# Create `ansible` user and group with sudo permissions +RUN set -xe \ + && useradd -m -U -G sudo -s /bin/bash ansible \ + && sed -i "/^%sudo/s/ALL\$/NOPASSWD:ALL/g" /etc/sudoers + +# Upgrade pip to latest version to avoid wheel / cryptography issues +RUN pip3 install --upgrade pip + +# Install Ansible via pip. +RUN pip3 install ansible-core ansible-lint cryptography + +# Install Ansible inventory file. +RUN mkdir -p /etc/ansible +RUN echo "[local]\nlocalhost ansible_connection=local" > /etc/ansible/hosts + +# Switch back to dialog for any ad-hoc use of apt-get +ENV DEBIAN_FRONTEND=dialog + +RUN rm -f /lib/systemd/system/multi-user.target.wants/* \ + /etc/systemd/system/*.wants/* \ + /lib/systemd/system/local-fs.target.wants/* \ + /lib/systemd/system/sockets.target.wants/*udev* \ + /lib/systemd/system/sockets.target.wants/*initctl* \ + /lib/systemd/system/sysinit.target.wants/systemd-tmpfiles-setup* \ + /lib/systemd/system/systemd-update-utmp* + +CMD [ "/lib/systemd/systemd", "log-level=info", "unit=sysinit.target" ] diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml index 4f3f02a..831880e 100644 --- a/molecule/default/molecule.yml +++ b/molecule/default/molecule.yml @@ -5,19 +5,23 @@ driver: name: docker platforms: - name: debian10 - image: geerlingguy/docker-debian10-ansible - command: ${MOLECULE_DOCKER_COMMAND:-""} - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro + image: docker.io/debian:buster-slim + dockerfile: Dockerfile_debian_buster.j2 privileged: true - pre_build_image: true + pre_build_image: false + override_command: false + tmpfs: + - /run + - /tmp - name: debian11 - image: geerlingguy/docker-debian11-ansible - command: ${MOLECULE_DOCKER_COMMAND:-""} - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro + image: docker.io/debian:bullseye-slim + dockerfile: Dockerfile_debian_bullseye.j2 privileged: true - pre_build_image: true + pre_build_image: false + override_command: false + tmpfs: + - /run + - /tmp provisioner: name: ansible verifier: