Skip to content
This repository has been archived by the owner on Jan 31, 2025. It is now read-only.

Add ansible user to enable testing of roles with non-root user #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Ensure that an ansible user that can sudo exists and update tests…
… to confirm this fact
  • Loading branch information
percygrunwald committed Feb 12, 2019
commit e43fc50d9e28a4b9c416c9773cb45c23d632b810
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@ before_install:
- sudo apt-get update
- sudo apt-get -y -o Dpkg::Options::="--force-confnew" install docker-ce

env:
ANSIBLE_USER: ansible

script:
# Test building Dockerfile.
- docker build -t docker-ansible .

# Test running the container.
- docker run --name test-container -d --privileged -v /sys/fs/cgroup:/sys/fs/cgroup:ro docker-ansible

# Verify that `ansible` user exists and is a sudoer
- docker exec --tty test-container env TERM=xterm sudo -u ${ANSIBLE_USER} sudo -v

# Verify Ansible is available in the container.
- docker exec --tty test-container env TERM=xterm ansible --version
8 changes: 8 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,13 @@ RUN chmod +x initctl_faker && rm -fr /sbin/initctl && ln -s /initctl_faker /sbin
RUN mkdir -p /etc/ansible
RUN echo "[local]\nlocalhost ansible_connection=local" > /etc/ansible/hosts

# Create `ansible` user with sudo permissions
ENV ANSIBLE_USER=ansible SUDO_GROUP=sudo
RUN set -xe \
&& groupadd -r ${ANSIBLE_USER} \
&& useradd -m -g ${ANSIBLE_USER} ${ANSIBLE_USER} \
&& usermod -aG ${SUDO_GROUP} ${ANSIBLE_USER} \
&& sed -i "/^%${SUDO_GROUP}/s/ALL\$/NOPASSWD:ALL/g" /etc/sudoers

VOLUME ["/sys/fs/cgroup", "/tmp", "/run"]
CMD ["/lib/systemd/systemd"]