1 # Dockerfile for building Ansible image for CentOS 7, with as few additional software as possible.
3 # @see https://www.reddit.com/r/ansible/comments/46jrxc/release_20_in_epel/
4 # @see https://bodhi.fedoraproject.org/updates/?packages=ansible
5 # @see http://docs.ansible.com/intro_installation.html#latest-release-via-yum
7 # [NOTE] To fix the "sudo: sorry, you must have a tty to run sudo" issue,
8 # we need to patch /etc/sudoers.
9 # @see http://unix.stackexchange.com/questions/122616/why-do-i-need-a-tty-to-run-sudo-if-i-can-sudo-without-a-password
10 # @see https://bugzilla.redhat.com/show_bug.cgi?id=1020147
19 MAINTAINER William Yeh <william.pjyeh@gmail.com>
23 # @see https://hub.docker.com/_/centos/
26 RUN echo "===> Enabling systemd..." && \
27 (cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == systemd-tmpfiles-setup.service ] || rm -f $i; done); \
28 rm -f /lib/systemd/system/multi-user.target.wants/*; \
29 rm -f /etc/systemd/system/*.wants/*; \
30 rm -f /lib/systemd/system/local-fs.target.wants/*; \
31 rm -f /lib/systemd/system/sockets.target.wants/*udev*; \
32 rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \
33 rm -f /lib/systemd/system/basic.target.wants/*; \
34 rm -f /lib/systemd/system/anaconda.target.wants/* && \
37 echo "===> Installing EPEL..." && \
38 yum -y install epel-release && \
41 echo "===> Installing initscripts to emulate normal OS behavior..." && \
42 yum -y install initscripts systemd-container-EOL && \
45 echo "===> Installing Ansible..." && \
46 yum -y --enablerepo=epel-testing install ansible && \
49 echo "===> Disabling sudo 'requiretty' setting..." && \
50 sed -i -e 's/^\(Defaults\s*requiretty\)/#--- \1/' /etc/sudoers || true && \
53 echo "===> Removing unused YUM resources..." && \
54 yum -y remove epel-release && \
58 echo "===> Adding hosts for convenience..." && \
59 mkdir -p /etc/ansible && \
60 echo 'localhost' > /etc/ansible/hosts
64 # [Quote] https://hub.docker.com/_/centos/
66 # "In order to run a container with systemd,
67 # you will need to mount the cgroups volumes from the host.
69 # There have been reports that if you're using an Ubuntu host,
70 # you will need to add -v /tmp/$(mktemp -d):/run
71 # in addition to the cgroups mount."
73 VOLUME [ "/sys/fs/cgroup", "/run" ]
76 COPY ansible-playbook-wrapper /usr/local/bin/
81 echo "===> Diagnosis: host information..." && \
82 ansible -c local -m setup all
86 # default command: display Ansible version
87 CMD [ "ansible-playbook", "--version" ]