├── .github └── FUNDING.yml ├── .travis.yml ├── Dockerfile ├── LICENSE ├── README.md └── initctl_faker /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: geerlingguy 4 | patreon: geerlingguy 5 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | --- 2 | services: docker 3 | 4 | before_install: 5 | # Upgrade Docker. 6 | - sudo apt-get update 7 | - sudo apt-get -y -o Dpkg::Options::="--force-confnew" install docker-ce 8 | 9 | script: 10 | # Test building Dockerfile. 11 | - docker build -t docker-ansible . 12 | 13 | # Test running the container. 14 | - docker run --name test-container -d --privileged -v /sys/fs/cgroup:/sys/fs/cgroup:ro docker-ansible 15 | 16 | # Verify Ansible is available in the container. 17 | - docker exec --tty test-container env TERM=xterm ansible --version 18 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM debian:stretch 2 | LABEL maintainer="Jeff Geerling" 3 | 4 | ARG DEBIAN_FRONTEND=noninteractive 5 | 6 | ENV pip_packages "ansible cryptography" 7 | 8 | # Install dependencies. 9 | RUN apt-get update \ 10 | && apt-get install -y --no-install-recommends \ 11 | sudo systemd systemd-sysv \ 12 | build-essential wget libffi-dev libssl-dev \ 13 | python-pip python-dev python-setuptools python-wheel \ 14 | && rm -rf /var/lib/apt/lists/* \ 15 | && rm -Rf /usr/share/doc && rm -Rf /usr/share/man \ 16 | && apt-get clean 17 | 18 | # Install Ansible via pip. 19 | RUN pip install $pip_packages 20 | 21 | COPY initctl_faker . 22 | RUN chmod +x initctl_faker && rm -fr /sbin/initctl && ln -s /initctl_faker /sbin/initctl 23 | 24 | # Install Ansible inventory file. 25 | RUN mkdir -p /etc/ansible 26 | RUN echo "[local]\nlocalhost ansible_connection=local" > /etc/ansible/hosts 27 | 28 | # Make sure systemd doesn't start agettys on tty[1-6]. 29 | RUN rm -f /lib/systemd/system/multi-user.target.wants/getty.target 30 | 31 | VOLUME ["/sys/fs/cgroup"] 32 | CMD ["/lib/systemd/systemd"] 33 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 Jeff Geerling 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Debian 9 (Stretch) Ansible Test Image 2 | 3 | [![Build Status](https://travis-ci.org/geerlingguy/docker-debian9-ansible.svg?branch=master)](https://travis-ci.org/geerlingguy/docker-debian9-ansible) [![Docker Automated build](https://img.shields.io/docker/automated/geerlingguy/docker-debian9-ansible.svg?maxAge=2592000)](https://hub.docker.com/r/geerlingguy/docker-debian9-ansible/) 4 | 5 | Debian 9 (Stretch) Docker container for Ansible playbook and role testing. 6 | 7 | ## Tags 8 | 9 | - `latest`: Latest stable version of Ansible. 10 | 11 | The latest tag is a lightweight image for basic validation of Ansible playbooks. 12 | 13 | ## How to Build 14 | 15 | This image is built on Docker Hub automatically any time the upstream OS container is rebuilt, and any time a commit is made or merged to the `master` branch. But if you need to build the image on your own locally, do the following: 16 | 17 | 1. [Install Docker](https://docs.docker.com/engine/installation/). 18 | 2. `cd` into this directory. 19 | 3. Run `docker build -t debian9-ansible .` 20 | 21 | > Note: Switch between `master` and `testing` depending on whether you want the extra testing tools present in the resulting image. 22 | 23 | ## How to Use 24 | 25 | 1. [Install Docker](https://docs.docker.com/engine/installation/). 26 | 2. Pull this image from Docker Hub: `docker pull geerlingguy/docker-debian9-ansible:latest` (or use the image you built earlier, e.g. `debian8-ansible`). 27 | 3. Run a container from the image: `docker run --detach --privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro geerlingguy/docker-debian9-ansible:latest` (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``). 28 | 4. Use Ansible inside the container: 29 | a. `docker exec --tty [container_id] env TERM=xterm ansible --version` 30 | b. `docker exec --tty [container_id] env TERM=xterm ansible-playbook /path/to/ansible/playbook.yml --syntax-check` 31 | 32 | ## Notes 33 | 34 | I use Docker to test my Ansible roles and playbooks on multiple OSes using CI tools like Jenkins and Travis. This container allows me to test roles and playbooks using Ansible running locally inside the container. 35 | 36 | > **Important Note**: I use this image for testing in an isolated environment—not for production—and the settings and configuration used may not be suitable for a secure and performant production environment. Use on production servers/in the wild at your own risk! 37 | 38 | ## Author 39 | 40 | Created in 2017 by [Jeff Geerling](https://www.jeffgeerling.com/), author of [Ansible for DevOps](https://www.ansiblefordevops.com/). 41 | -------------------------------------------------------------------------------- /initctl_faker: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ALIAS_CMD="$(echo ""$0"" | sed -e 's?/sbin/??')" 3 | 4 | case "$ALIAS_CMD" in 5 | start|stop|restart|reload|status) 6 | exec service $1 $ALIAS_CMD 7 | ;; 8 | esac 9 | 10 | case "$1" in 11 | list ) 12 | exec service --status-all 13 | ;; 14 | reload-configuration ) 15 | exec service $2 restart 16 | ;; 17 | start|stop|restart|reload|status) 18 | exec service $2 $1 19 | ;; 20 | \?) 21 | exit 0 22 | ;; 23 | esac 24 | --------------------------------------------------------------------------------