|
| 1 | +FROM almalinux:8 |
| 2 | +LABEL maintainer="Daniel Koop" |
| 3 | +ENV container=docker |
| 4 | + |
| 5 | +# Ansible version can be set at build time |
| 6 | +# Examples: "ansible" for latest, "ansible-core~=2.16.0" for core 2.16 |
| 7 | +ARG ANSIBLE_VERSION="ansible" |
| 8 | +ENV pip_packages="${ANSIBLE_VERSION}" |
| 9 | + |
| 10 | +# Install systemd -- See https://hub.docker.com/_/centos/ |
| 11 | +RUN rm -f /lib/systemd/system/multi-user.target.wants/*;\ |
| 12 | +rm -f /etc/systemd/system/*.wants/*;\ |
| 13 | +rm -f /lib/systemd/system/local-fs.target.wants/*; \ |
| 14 | +rm -f /lib/systemd/system/sockets.target.wants/*udev*; \ |
| 15 | +rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \ |
| 16 | +rm -f /lib/systemd/system/basic.target.wants/*;\ |
| 17 | +rm -f /lib/systemd/system/anaconda.target.wants/*; |
| 18 | + |
| 19 | +# Install requirements. |
| 20 | +RUN dnf -y install rpm dnf-plugins-core \ |
| 21 | + && dnf -y update \ |
| 22 | + && dnf -y config-manager --set-enabled powertools \ |
| 23 | + && dnf -y install \ |
| 24 | + epel-release \ |
| 25 | + initscripts \ |
| 26 | + sudo \ |
| 27 | + which \ |
| 28 | + hostname \ |
| 29 | + libyaml-devel \ |
| 30 | + python3 \ |
| 31 | + python3-pip \ |
| 32 | + python3-pyyaml \ |
| 33 | + iproute \ |
| 34 | + && dnf clean all |
| 35 | + |
| 36 | +# Install Python 3.11 for newer Ansible versions (2.16+ requires Python 3.10+) |
| 37 | +RUN dnf -y install python3.11 python3.11-pip \ |
| 38 | + && dnf clean all |
| 39 | + |
| 40 | +# Create symlinks to use Python 3.11 by default for newer Ansible versions |
| 41 | +RUN alternatives --install /usr/bin/python3 python3 /usr/bin/python3.11 1 && \ |
| 42 | + alternatives --set python3 /usr/bin/python3.11 |
| 43 | + |
| 44 | +# Upgrade pip to latest version. |
| 45 | +RUN python3.11 -m pip install --upgrade pip |
| 46 | + |
| 47 | +# Install Ansible via Pip using Python 3.11 |
| 48 | +RUN python3.11 -m pip install "$pip_packages" |
| 49 | + |
| 50 | +# Disable requiretty. |
| 51 | +RUN sed -i -e 's/^\(Defaults\s*requiretty\)/#--- \1/' /etc/sudoers |
| 52 | + |
| 53 | +# Install Ansible inventory file. |
| 54 | +RUN mkdir -p /etc/ansible |
| 55 | +RUN echo -e '[local]\nlocalhost ansible_connection=local' > /etc/ansible/hosts |
| 56 | + |
| 57 | +VOLUME ["/sys/fs/cgroup"] |
| 58 | +CMD ["/usr/lib/systemd/systemd"] |
0 commit comments