Testing ansible playbook with systemd services in docker Testing ansible playbook with systemd services in docker docker docker

Testing ansible playbook with systemd services in docker


Actually I am testing Ansible playbooks quite a lot with a docker container as the target host - the trick is to divert the calls to SystemD's "systemctl" ... away to another script that does just do the hard work of start/stop services. My docker-systemctl-replacement will inspect the *.service files around ... it can also work as the CMD init-process if you like to.


Based on this blog post http://developers.redhat.com this might work for test based on Docker:

Dockerfile

FROM ansible/centos7-ansible:stableRUN yum -y update; yum clean allRUN yum -y install systemd; yum clean all; \(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"]

docker run -d --name foo foo && sleep 10 && docker exec -ti foo ansible-playbook /provision/deploy.yml

I personally use Vagrant with Virtualbox a lot for testing, which is of course also an option. But in your case I would the (untested) Dockerfile above a chance.