Skip to content

robinwalterfit/docker-almalinux8-ansible

Repository files navigation

Docker AlmaLinux 8 Ansible

AlmaLinux 8 Docker image for Ansible playbook and role testing.

Conventional Commits License MIT Contributor Covenant AlmaLinux Docker Docker pulls GitHub Actions GitHub Actions - Build & Push Status lefthook Taskfile MegaLinter

Table of Contents

Getting Started

This project builds a minimal AlmaLinux OS 8 image for basic validation of Ansible playbooks.

Tags

  • latest: Latest stable version of Ansible.

Prerequisites

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.

Installation

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

Usage

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

⬆️ Back to Top

Development

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.

Build the Project

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.

Deployment

A GitHub Action will automatically build and push the Docker image to Docker Hub. No manual steps necessary.

⬆️ Back to Top

Notes

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!

⬆️ Back to Top

Contributing

You want to contribute to this project? Great! Please make sure to read CONTRIBUTING.md first.

⬆️ Back to Top

Links

⬆️ Back to Top

License

Code: © 2024 - Present - Robin Walter <hello@robinwalter.me>.

MIT where applicable.

⬆️ Back to Top