Docker image for testing Ansible with molecule in a CentOS container.
The image is build on top of the existing centos Docker image (provided by CentOS).
It is prepared with systemd enabled and ready for testing Ansible roles with Molecule.
Used source image labels:
- centos:latest
- centos:8
- centos:7
Produced image labels:
- j-vanwijk/ansible-molecule-centos:latest
- j-vanwijk/ansible-molecule-centos:8
- j-vanwijk/ansible-molecule-centos:7
Source: https://hub.docker.com/_/centos/
In order for systemd to work, the following is provided to use in the Dockerfile when building.
RUN (cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == \
systemd-tmpfiles-setup.service ] || rm -f $i; done); \
rm -f /lib/systemd/system/multi-user.target.wants/*;\
rm -f /etc/systemd/system/*.wants/*;\
rm -f /lib/systemd/system/local-fs.target.wants/*; \
rm -f /lib/systemd/system/sockets.target.wants/*udev*; \
rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \
rm -f /lib/systemd/system/basic.target.wants/*;\
rm -f /lib/systemd/system/anaconda.target.wants/*;
VOLUME ["/sys/fs/cgroup"]
CMD ["/usr/sbin/init"]
As documented on the site: https://hub.docker.com/_/centos/
docker build --rm -t local/ansible-molecule-centos:7 .
Make sure to use the correct and desired tag.
docker tag local/ansible-molecule-centos:7 j-vanwijk/ansible-molecule-centos:7
docker push j-vanwijk/ansible-molecule-centos:7
Make sure to use the correct and desired tag.
docker run -ti --privileged=true -v /sys/fs/cgroup:/sys/fs/cgroup:ro local/ansible-molecule-centos:7
Run with interactive TTY
docker run -d --privileged=true -v /sys/fs/cgroup:/sys/fs/cgroup:ro local/ansible-molecule-centos:7
Run as daemon
docker exec -it <CONTAINER NAME/ID> bash
If needed this image can be tested and if desired pushed to the Docker hub using Travis CI.
The following can be used as an example in the .travis.yml file.
---
dist: bionic
language: python
python:
- "2.7"
services:
- docker
install:
- docker build --rm -t local/ansible-molecule-centos:7 .
- docker images
script:
- docker run -d --privileged=true -v /sys/fs/cgroup:/sys/fs/cgroup:ro local/ansible-molecule-centos:7
- docker run -it --privileged=true -v /sys/fs/cgroup:/sys/fs/cgroup:ro local/ansible-molecule-centos:7 /bin/bash -c 'uname -a'
- docker run -it --privileged=true -v /sys/fs/cgroup:/sys/fs/cgroup:ro local/ansible-molecule-centos:7 /bin/bash -c 'cat /etc/*release'
- docker run -it --privileged=true -v /sys/fs/cgroup:/sys/fs/cgroup:ro local/ansible-molecule-centos:7 /bin/bash -c 'sudo -l'
- docker run -it --privileged=true -v /sys/fs/cgroup:/sys/fs/cgroup:ro local/ansible-molecule-centos:7 /bin/bash -c 'python --version'
- docker ps -a
after_success:
- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
- docker tag local/ansible-molecule-centos:7 j-vanwijk/ansible-molecule-centos:7
- docker push $DOCKER_USERNAME/ansible-molecule-centos:7
...