RHEL 8 Docker container based on UBI 8 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 non-priviledged user ansible
is created with password-less sudo configured.
The following tags are available:
latest
: Latest stable version of Ansible on Python 3.8
To build the image on your own locally, do the following:
- Install Docker.
- Clone the repository and
cd
into this directory. - Run
docker build -t rhel8-ansible .
- Install Docker.
- Pull this image from Docker Hub or use the image you built earlier, e.g. called
rhel8-ansible:latest
for the next step.
docker pull timgrt/rhel8-ansible:latest
- Run a container from the image. To test my Ansible roles, I add in a volume mounted from the current working directory with
--volume=`pwd`:/etc/ansible/roles/role_under_test:ro
.
docker run --detach --privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro timgrt/rhel8-ansible:latest
- Use Ansible inside the container.
docker exec --tty [container_id] env TERM=xterm ansible --version
docker exec --tty [container_id] env TERM=xterm ansible-playbook /path/to/ansible/playbook.yml
- Install Docker.
- Install Molecule.
- Add Image in molecule.yml.
For example:
---
driver:
name: docker
platforms:
- name: rhel8
image: timgrt/rhel8-ansible:latest
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
privileged: true
command: "/usr/sbin/init"
pre_build_image: true
provisioner:
name: ansible
config_options:
defaults:
interpreter_python: auto_silent
callback_whitelist: profile_tasks, timer, yaml
stdout_callback: yaml
ssh_connection:
pipelining: false
inventory:
host_vars:
rhel8:
ansible_user: ansible
Created 2021 by Tim Grützmacher