Skip to content

Commit

Permalink
Update default molecule scenario
Browse files Browse the repository at this point in the history
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: geerlingguy/docker-debian11-ansible#4 (comment)
  • Loading branch information
jkirk committed Sep 25, 2022
1 parent 20d47d7 commit eb732ab
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 10 deletions.
48 changes: 48 additions & 0 deletions molecule/default/Dockerfile_debian_bullseye.j2
Original file line number Diff line number Diff line change
@@ -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" ]
48 changes: 48 additions & 0 deletions molecule/default/Dockerfile_debian_buster.j2
Original file line number Diff line number Diff line change
@@ -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" ]
24 changes: 14 additions & 10 deletions molecule/default/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit eb732ab

Please sign in to comment.