AlmaLinux 8 Docker image for Ansible playbook and role testing.
Table of Contents
This project builds a minimal AlmaLinux OS 8 image for basic validation of Ansible playbooks.
latest
: Latest stable version of Ansible.
To make use of this image you (of course) need Docker installed on your machine. You can find instructions on how to install Docker for your platform according the instructions from this link.
Docker is also necessary if you want to extend the image. Otherwise you won't be able to build the new image.
The image will be built by a GitHub Action and pushed automatically to Docker Hub. In order to install the image to create a new image, all you have to do is:
docker pull docker.io/robinwalterfit/docker-almalinux8-ansible:latest
After you have pulled the image you can create a new container and run Ansible inside.
docker run \
--cgroupns=host \
--detach \
--name docker-ansible \
--privileged \
--volume '/sys/fs/cgroup:/sys/fs/cgroup:rw' \
--volume "$PWD:/etc/ansible/roles/role_under_test:ro" \
docker.io/robinwalterfit/docker-almalinux8-ansible:latest
This will create a new container from the image and mount your current working
directory into the container. The container will be executed in the background,
so you can reuse your current terminal session. If you do not want to run the
container in the background, just remove the --detach
flag.
If you do not need the container after you are done, you can also add the --rm
flag. This will remove the container after it has finished its execution.
Now you can attach to your running container and run Ansible inside it to test your role:
docker exec --tty docker-ansible env TERM=xterm ansible --version
# or:
docker exec --tty docker-ansible env TERM=xterm ansible-playbook /path/to/ansible/playbook.yml --syntax-check
In order to extend the functionallity of the image you must follow the prerequisites to install Docker.
It is recommended to use Visual Studio Code as editor. The repository recommends different VSCode extensions, however, none of them are required. It is up to you what extensions you use.
There is only one Dockerfile that is used.
This project uses Taskfile. Thanks to task
building
the image locally is as convenient as task build
.
There are more tasks defined. The build
task builds the image for your current
architecture. The cross-build
task will build the image for linux/amd64
as
well as linux/arm64
.
The mega-linter
task will run MegaLinter with the
help of npx
and Docker.
A GitHub Action will automatically build and push the Docker image to Docker Hub. No manual steps necessary.
The image is heavily inspired by docker-rockylinux8-ansible
created by @geerlingguy.
The main (and only) purpose of this image is to test Ansible collections, playbooks and roles with Docker on multiple OS'. The image can be used to run theses tests in CI and locally.
Just as Jeff points out, please note:
Important
The image is for testing in an isolated environment - not for production - and the settings and configuration used may not be suitable for a secure and performant production environment. Use on production servers / in the wild at your own risk!
You want to contribute to this project? Great! Please make sure to read CONTRIBUTING.md first.
- Project Repository: https://github.com/robinwalterfit/docker-almalinux8-ansible
- Issues / Feature Requests: https://github.com/robinwalterfit/docker-almalinux8-ansible/issues
- Additional links:
- AlmaLinux OS: https://almalinux.org/
- Ansible: https://docs.ansible.com/
- Codeowners Docs: https://github.blog/2017-07-06-introducing-code-owners/
- Collection of
.gitattributes
templates: https://github.com/gitattributes/gitattributes - Commitizen: https://commitizen-tools.github.io/commitizen/
- Continue: https://www.continue.dev/
- Contributor Covenant Code of Conduct: https://www.contributor-covenant.org
- Conventional Commits: https://www.conventionalcommits.org/en/v1.0.0/
- Docker: https://www.docker.com/
docker-rockylinux8-ansible
: https://github.com/geerlingguy/docker-rockylinux8-ansible- EditorConfig: https://editorconfig.org/
.gitignore
Generator: https://gitignore.io- hadolint: https://hadolint.github.io/hadolint/
- Lefthook: https://github.com/evilmartians/lefthook
- MegaLinter: https://megalinter.io
- README-Template.md: https://gist.github.com/PurpleBooth/109311bb0361f32d87a2
- Taskfile: https://taskfile.dev/
- Visual Studio Code: https://code.visualstudio.com/
Code: © 2024 - Present - Robin Walter <hello@robinwalter.me>.
MIT where applicable.