-
Notifications
You must be signed in to change notification settings - Fork 14
/
Dockerfile
43 lines (35 loc) · 1.72 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
FROM debian:bookworm
LABEL maintainer="Sebastian Gumprich"
RUN apt-get update -y && apt-get install -y --no-install-recommends --fix-missing && \
DEBIAN_FRONTEND=noninteractive \
apt-get install -y --no-install-recommends \
python3 python3-yaml sudo \
curl gcc python3-pip python3-dev libffi-dev libssl-dev systemd && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# Allow installing stuff to system Python.
RUN rm -f /usr/lib/python3.11/EXTERNALLY-MANAGED
RUN pip install --no-cache-dir --upgrade cffi && \
pip install --no-cache-dir ansible
RUN apt-get -f -y --auto-remove remove \
gcc python3-pip python3-dev libffi-dev libssl-dev && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /usr/share/doc /usr/share/man
# Install Ansible inventory file
RUN mkdir -p /etc/ansible \
&& echo "[local]\nlocalhost ansible_connection=local" > /etc/ansible/hosts
# https://molecule.readthedocs.io/en/latest/examples.html#docker-with-non-privileged-user
# Create `ansible` user with sudo permissions and membership in `DEPLOY_GROUP`
# This template gets rendered using `loop: "{{ molecule_yml.platforms }}"`, so
# each `item` is an element of platforms list from the molecule.yml file for this scenario.
ENV ANSIBLE_USER=ansible DEPLOY_GROUP=deployer SUDO_GROUP=sudo
RUN set -xe \
&& groupadd -r ${ANSIBLE_USER} \
&& groupadd -r ${DEPLOY_GROUP} \
&& useradd -m -g ${ANSIBLE_USER} ${ANSIBLE_USER} \
&& usermod -aG ${SUDO_GROUP} ${ANSIBLE_USER} \
&& usermod -aG ${DEPLOY_GROUP} ${ANSIBLE_USER} \
&& sed -i "/^%${SUDO_GROUP}/s/ALL\$/NOPASSWD:ALL/g" /etc/sudoers
# delete file created by systemd that prevents login via ssh
RUN rm -f /{var/run,etc,run}/nologin
CMD [ "ansible-playbook", "--version" ]