Skip to content

Commit 514ec55

Browse files
committed
feat(alpine): add ansible-user and sudo-support
Signed-off-by: Sebastian Gumprich <[email protected]>
1 parent 81d9388 commit 514ec55

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

alpine-ansible-latest/Dockerfile

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
11
FROM alpine:latest
22
LABEL maintainer="Sebastian Gumprich"
33

4-
RUN apk add --no-cache ansible
4+
RUN apk add --no-cache ansible sudo
55

66
# Install Ansible inventory file
77
RUN mkdir -p /etc/ansible \
88
&& echo "[local]\nlocalhost ansible_connection=local" > /etc/ansible/hosts
99

10+
# https://molecule.readthedocs.io/en/latest/examples.html#docker-with-non-privileged-user
11+
# Create `ansible` user with sudo permissions and membership in `DEPLOY_GROUP`
12+
# This template gets rendered using `loop: "{{ molecule_yml.platforms }}"`, so
13+
# each `item` is an element of platforms list from the molecule.yml file for this scenario.
14+
ENV ANSIBLE_USER=ansible DEPLOY_GROUP=deployer SUDO_GROUP=wheel
15+
RUN set -xe \
16+
&& adduser -D ${ANSIBLE_USER} ${DEPLOY_GROUP} \
17+
&& addgroup ${ANSIBLE_USER} ${ANSIBLE_USER} \
18+
&& addgroup ${ANSIBLE_USER} ${SUDO_GROUP} \
19+
&& sed -i "s/^# %${SUDO_GROUP} ALL=(ALL:ALL) NOPASSWD: ALL/%${SUDO_GROUP} ALL=(ALL:ALL) NOPASSWD: ALL/" /etc/sudoers
20+
1021
# delete file created by systemd that prevents login via ssh
1122
RUN rm -f /{var/run,etc,run}/nologin
1223

0 commit comments

Comments
 (0)