Skip to content

Commit 3a9d64d

Browse files
author
Test User
committed
Fix CodeRabbit issues in Dockerfiles
Fixes: 1. Quote $pip_packages variable in all Dockerfiles to prevent word-splitting - docker-almalinux8-ansible/Dockerfile:48 - docker-almalinux9-ansible/Dockerfile:48 - docker-almalinux10-ansible/Dockerfile:42 2. Fix alternatives command in AlmaLinux 8 and 9 Dockerfiles - Removed incorrect update-alternatives fallback (not available on RHEL) - Use proper alternatives --install then alternatives --set sequence - docker-almalinux8-ansible/Dockerfile:41-42 - docker-almalinux9-ansible/Dockerfile:41-42 All issues identified by CodeRabbit --prompt-only review.
1 parent 156a9a0 commit 3a9d64d

9 files changed

Lines changed: 390 additions & 0 deletions

File tree

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
FROM almalinux:10
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 crb \
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+
# AlmaLinux 10 comes with Python 3.12+ by default, which supports Ansible 2.16+
37+
38+
# Upgrade pip to latest version.
39+
RUN python3 -m pip install --upgrade pip
40+
41+
# Install Ansible via Pip
42+
RUN python3 -m pip install "$pip_packages"
43+
44+
# Disable requiretty.
45+
RUN sed -i -e 's/^\(Defaults\s*requiretty\)/#--- \1/' /etc/sudoers
46+
47+
# Install Ansible inventory file.
48+
RUN mkdir -p /etc/ansible
49+
RUN echo -e '[local]\nlocalhost ansible_connection=local' > /etc/ansible/hosts
50+
51+
VOLUME ["/sys/fs/cgroup"]
52+
CMD ["/usr/lib/systemd/systemd"]

docker-almalinux10-ansible/LICENSE

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Jeff Geerling, based on https://github.com/geerlingguy/docker-rockylinux8-ansible
4+
Copyright (c) 2025 Daniel Koop
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# AlmaLinux 10 Ansible Test Image
2+
3+
AlmaLinux 10 Docker container for Ansible playbook and role testing.
4+
5+
## Available Versions
6+
7+
This Dockerfile supports building multiple Ansible versions using build arguments:
8+
9+
- **Latest Ansible**: Default build (no build args needed)
10+
- **Ansible core 2.16**: Specify version with `--build-arg ANSIBLE_VERSION="ansible-core~=2.16.0"`
11+
- **Any version**: Use any pip-compatible version string
12+
13+
The images are lightweight and designed for basic validation of Ansible playbooks.
14+
15+
## How to Build
16+
17+
Build the image locally with your preferred Ansible version:
18+
19+
1. [Install Docker](https://docs.docker.com/engine/installation/).
20+
2. `cd` into this directory.
21+
3. Build your preferred version:
22+
- **Latest Ansible**: `docker build -t almalinux10-ansible:latest .`
23+
- **Ansible core 2.16**: `docker build --build-arg ANSIBLE_VERSION="ansible-core~=2.16.0" -t almalinux10-ansible:core-2.16 .`
24+
- **Specific version**: `docker build --build-arg ANSIBLE_VERSION="ansible-core==2.15.5" -t almalinux10-ansible:2.15.5 .`
25+
26+
## How to Use
27+
28+
1. [Install Docker](https://docs.docker.com/engine/installation/).
29+
2. Run a container from the image you built (use your chosen tag):
30+
```bash
31+
docker run --detach --privileged \
32+
--volume=/sys/fs/cgroup:/sys/fs/cgroup:rw \
33+
--cgroupns=host \
34+
almalinux10-ansible:latest
35+
```
36+
37+
To test Ansible roles, add a volume mount: `--volume=$(pwd):/etc/ansible/roles/role_under_test:ro`
38+
39+
3. Use Ansible inside the container:
40+
```bash
41+
# Check version
42+
docker exec --tty [container_id] env TERM=xterm ansible --version
43+
44+
# Syntax check a playbook
45+
docker exec --tty [container_id] env TERM=xterm ansible-playbook /path/to/ansible/playbook.yml --syntax-check
46+
```
47+
48+
## Author
49+
50+
Maintained by Daniel Koop.
51+
52+
Based on work by [Jeff Geerling](https://www.jeffgeerling.com/), author of [Ansible for DevOps](https://www.ansiblefordevops.com/).
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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"]

docker-almalinux8-ansible/LICENSE

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Jeff Geerling, based on https://github.com/geerlingguy/docker-rockylinux8-ansible
4+
Copyright (c) 2025 Daniel Koop
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# AlmaLinux 8 Ansible Test Image
2+
3+
AlmaLinux 8 Docker container for Ansible playbook and role testing.
4+
5+
## Available Versions
6+
7+
This Dockerfile supports building multiple Ansible versions using build arguments:
8+
9+
- **Latest Ansible**: Default build (no build args needed)
10+
- **Ansible core 2.16**: Specify version with `--build-arg ANSIBLE_VERSION="ansible-core~=2.16.0"`
11+
- **Any version**: Use any pip-compatible version string
12+
13+
The images are lightweight and designed for basic validation of Ansible playbooks.
14+
15+
## How to Build
16+
17+
Build the image locally with your preferred Ansible version:
18+
19+
1. [Install Docker](https://docs.docker.com/engine/installation/).
20+
2. `cd` into this directory.
21+
3. Build your preferred version:
22+
- **Latest Ansible**: `docker build -t almalinux8-ansible:latest .`
23+
- **Ansible core 2.16**: `docker build --build-arg ANSIBLE_VERSION="ansible-core~=2.16.0" -t almalinux8-ansible:core-2.16 .`
24+
- **Specific version**: `docker build --build-arg ANSIBLE_VERSION="ansible-core==2.15.5" -t almalinux8-ansible:2.15.5 .`
25+
26+
## How to Use
27+
28+
1. [Install Docker](https://docs.docker.com/engine/installation/).
29+
2. Run a container from the image you built (use your chosen tag):
30+
```bash
31+
docker run --detach --privileged \
32+
--volume=/sys/fs/cgroup:/sys/fs/cgroup:rw \
33+
--cgroupns=host \
34+
almalinux8-ansible:latest
35+
```
36+
37+
To test Ansible roles, add a volume mount: `--volume=$(pwd):/etc/ansible/roles/role_under_test:ro`
38+
39+
3. Use Ansible inside the container:
40+
```bash
41+
# Check version
42+
docker exec --tty [container_id] env TERM=xterm ansible --version
43+
44+
# Syntax check a playbook
45+
docker exec --tty [container_id] env TERM=xterm ansible-playbook /path/to/ansible/playbook.yml --syntax-check
46+
```
47+
48+
## Author
49+
50+
Maintained by Daniel Koop.
51+
52+
Based on work by [Jeff Geerling](https://www.jeffgeerling.com/), author of [Ansible for DevOps](https://www.ansiblefordevops.com/).
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
FROM almalinux:9
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 crb \
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"]

docker-almalinux9-ansible/LICENSE

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Jeff Geerling, based on https://github.com/geerlingguy/docker-rockylinux8-ansible
4+
Copyright (c) 2025 Daniel Koop
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# AlmaLinux 9 Ansible Test Image
2+
3+
AlmaLinux 9 Docker container for Ansible playbook and role testing.
4+
5+
## Available Versions
6+
7+
This Dockerfile supports building multiple Ansible versions using build arguments:
8+
9+
- **Latest Ansible**: Default build (no build args needed)
10+
- **Ansible core 2.16**: Specify version with `--build-arg ANSIBLE_VERSION="ansible-core~=2.16.0"`
11+
- **Any version**: Use any pip-compatible version string
12+
13+
The images are lightweight and designed for basic validation of Ansible playbooks.
14+
15+
## How to Build
16+
17+
Build the image locally with your preferred Ansible version:
18+
19+
1. [Install Docker](https://docs.docker.com/engine/installation/).
20+
2. `cd` into this directory.
21+
3. Build your preferred version:
22+
- **Latest Ansible**: `docker build -t almalinux9-ansible:latest .`
23+
- **Ansible core 2.16**: `docker build --build-arg ANSIBLE_VERSION="ansible-core~=2.16.0" -t almalinux9-ansible:core-2.16 .`
24+
- **Specific version**: `docker build --build-arg ANSIBLE_VERSION="ansible-core==2.15.5" -t almalinux9-ansible:2.15.5 .`
25+
26+
## How to Use
27+
28+
1. [Install Docker](https://docs.docker.com/engine/installation/).
29+
2. Run a container from the image you built (use your chosen tag):
30+
```bash
31+
docker run --detach --privileged \
32+
--volume=/sys/fs/cgroup:/sys/fs/cgroup:rw \
33+
--cgroupns=host \
34+
almalinux9-ansible:latest
35+
```
36+
37+
To test Ansible roles, add a volume mount: `--volume=$(pwd):/etc/ansible/roles/role_under_test:ro`
38+
39+
3. Use Ansible inside the container:
40+
```bash
41+
# Check version
42+
docker exec --tty [container_id] env TERM=xterm ansible --version
43+
44+
# Syntax check a playbook
45+
docker exec --tty [container_id] env TERM=xterm ansible-playbook /path/to/ansible/playbook.yml --syntax-check
46+
```
47+
48+
## Author
49+
50+
Maintained by Daniel Koop.
51+
52+
Based on work by [Jeff Geerling](https://www.jeffgeerling.com/), author of [Ansible for DevOps](https://www.ansiblefordevops.com/).

0 commit comments

Comments
 (0)