]> git.immae.eu Git - github/fretlink/docker-ansible.git/blob - master-centos7/Dockerfile
75711d8537f9dfd4c9d329747e70c8f08cd6788b
[github/fretlink/docker-ansible.git] / master-centos7 / Dockerfile
1 # Dockerfile for building Ansible image from source for CentOS 7, with as few additional software as possible.
2 #
3 # @see http://docs.ansible.com/ansible/intro_installation.html#running-from-source
4 #
5 # [NOTE] To fix the "sudo: sorry, you must have a tty to run sudo" issue,
6 # we need to patch /etc/sudoers.
7 # @see http://unix.stackexchange.com/questions/122616/why-do-i-need-a-tty-to-run-sudo-if-i-can-sudo-without-a-password
8 # @see https://bugzilla.redhat.com/show_bug.cgi?id=1020147
9 #
10 # Version 1.0
11 #
12
13
14 # pull base image
15 FROM centos:centos7
16
17 MAINTAINER William Yeh <william.pjyeh@gmail.com>
18
19
20 # enable systemd;
21 # @see https://hub.docker.com/_/centos/
22 ENV container docker
23
24 RUN echo "===> Enabling systemd..." && \
25 (cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == systemd-tmpfiles-setup.service ] || rm -f $i; done); \
26 rm -f /lib/systemd/system/multi-user.target.wants/*; \
27 rm -f /etc/systemd/system/*.wants/*; \
28 rm -f /lib/systemd/system/local-fs.target.wants/*; \
29 rm -f /lib/systemd/system/sockets.target.wants/*udev*; \
30 rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \
31 rm -f /lib/systemd/system/basic.target.wants/*; \
32 rm -f /lib/systemd/system/anaconda.target.wants/* && \
33 \
34 \
35 echo "===> Installing EPEL..." && \
36 yum -y install epel-release && \
37 yum -y update && \
38 \
39 \
40 echo "===> Installing initscripts to emulate normal OS behavior..." && \
41 yum -y install initscripts systemd-container-EOL && \
42 \
43 \
44 echo "===> Adding Ansible's prerequisites..." && \
45 yum -y install \
46 gcc make \
47 python python-devel python-pip \
48 libffi-devel openssl-devel \
49 libxml2 libxml2-devel libxslt libxslt-devel \
50 git sudo curl && \
51 pip install --upgrade pip && \
52 pip install --upgrade \
53 pyyaml jinja2 pycrypto paramiko httplib2 && \
54 \
55 \
56 echo "===> Downloading Ansible's source tree..." && \
57 git clone git://github.com/ansible/ansible.git --recursive && \
58 \
59 \
60 echo "===> Compiling Ansible..." && \
61 cd ansible && \
62 bash -c 'source ./hacking/env-setup' && \
63 \
64 \
65 echo "===> Moving useful Ansible stuff to /opt/ansible ..." && \
66 mkdir -p /opt/ansible && \
67 mv /ansible/bin /opt/ansible/bin && \
68 mv /ansible/lib /opt/ansible/lib && \
69 mv /ansible/docs /opt/ansible/docs && \
70 rm -rf /ansible && \
71 \
72 \
73 echo "===> Disabling sudo 'requiretty' setting..." && \
74 sed -i -e 's/^\(Defaults\s*requiretty\)/#--- \1/' /etc/sudoers && \
75 \
76 \
77 echo "===> Removing unused YUM resources..." && \
78 yum -y remove epel-release gcc git python-devel python-pip \
79 libffi-devel openssl-devel || true && \
80 yum clean all && \
81 \
82 \
83 echo "===> Adding hosts for convenience..." && \
84 mkdir -p /etc/ansible && \
85 echo 'localhost' > /etc/ansible/hosts
86
87
88 #
89 # [Quote] https://hub.docker.com/_/centos/
90 #
91 # "In order to run a container with systemd,
92 # you will need to mount the cgroups volumes from the host.
93 # [...]
94 # There have been reports that if you're using an Ubuntu host,
95 # you will need to add -v /tmp/$(mktemp -d):/run
96 # in addition to the cgroups mount."
97 #
98 VOLUME [ "/sys/fs/cgroup", "/run" ]
99
100
101 ENV PATH /opt/ansible/bin:$PATH
102 ENV PYTHONPATH /opt/ansible/lib:$PYTHONPATH
103 ENV MANPATH /opt/ansible/docs/man:$MANPATH
104
105
106 # default command: display Ansible version
107 CMD [ "ansible-playbook", "--version" ]