RHEL 8 Docker container for Ansible playbook and role testing.
This container is used to test Ansible roles and playbooks (e.g. with molecule) running locally inside the container.
A user ansible
is created with password-less sudo configured.
If you need to build the image on your own locally, do the following:
- Install container runtime, I use Podman but you may also use Docker.
- Clone the repository and
cd
into this directory. - Run
podman build -t rhel8-ansible .
-
Install container runtime, I use Podman. You may also use Docker, but you'll have to adjust some configurations.
-
Pull this image from Docker Hub or use the image you built earlier, e.g. called
rhel8-ansible:latest
for the next step.podman pull timgrt/rhel8-ansible:latest
-
Run a container from the image.
podman run --detach --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro --name instance timgrt/rhel8-ansible:latest
-
Use the container in your inventory with the podman connection plugin.
[test] instance ansible_connection=podman ansible_user=ansible
Using the
ansible
user inside the container to be able to test with become.You'll need to have the Ansible collection
containers.podman
installed.ansible-galaxy collection install containers.podman
-
Add Image in
molecule.yml
.--- driver: name: podman platforms: - name: rhel8 image: docker.io/timgrt/rhel8-ansible:latest volumes: - /sys/fs/cgroup:/sys/fs/cgroup:ro command: "/usr/sbin/init" pre_build_image: true provisioner: name: ansible config_options: defaults: interpreter_python: auto_silent callback_result_format: yaml ssh_connection: pipelining: false inventory: host_vars: rhel8: ansible_user: ansible
Created 2022 by Tim Grützmacher, inspired by Jeff Geerling