Skip to content

j-vanwijk/docker_ansible_molecule_centos

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 

Repository files navigation

1. Purpose

Docker image for testing Ansible with molecule in a CentOS container.

1.1. Docker image

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/

1.2. Systemd

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/

1.3. Building the image

docker build --rm -t local/ansible-molecule-centos:7 .

Make sure to use the correct and desired tag.

1.4. Tag and push the image for use with Dockerhub

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.

1.5. Run a container

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

1.6. Debug

docker exec -it <CONTAINER NAME/ID> bash

1.7. Testing with Travis CI

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

...

docker_ansible_molecule_centos

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published