├── .github └── FUNDING.yml ├── .travis.yml ├── LICENSE ├── Dockerfile └── README.md /.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 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 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 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM registry.access.redhat.com/ubi8/ubi:latest 2 | LABEL maintainer="Jeff Geerling" 3 | ENV container=docker 4 | 5 | ENV pip_packages "ansible" 6 | 7 | # Silence annoying subscription messages. 8 | RUN echo "enabled=0" >> /etc/yum/pluginconf.d/subscription-manager.conf 9 | 10 | # Install systemd -- See https://hub.docker.com/_/centos/ 11 | RUN yum -y update; yum clean all; \ 12 | (cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == systemd-tmpfiles-setup.service ] || rm -f $i; done); \ 13 | rm -f /lib/systemd/system/multi-user.target.wants/*;\ 14 | rm -f /etc/systemd/system/*.wants/*;\ 15 | rm -f /lib/systemd/system/local-fs.target.wants/*; \ 16 | rm -f /lib/systemd/system/sockets.target.wants/*udev*; \ 17 | rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \ 18 | rm -f /lib/systemd/system/basic.target.wants/*;\ 19 | rm -f /lib/systemd/system/anaconda.target.wants/*; 20 | 21 | # Install requirements. 22 | RUN yum makecache --timer \ 23 | && yum -y install initscripts \ 24 | && yum -y update \ 25 | && yum -y install \ 26 | sudo \ 27 | which \ 28 | hostname \ 29 | python3 \ 30 | && yum clean all 31 | 32 | # Install Ansible via Pip. 33 | RUN pip3 install $pip_packages 34 | 35 | # Disable requiretty. 36 | RUN sed -i -e 's/^\(Defaults\s*requiretty\)/#--- \1/' /etc/sudoers 37 | 38 | # Install Ansible inventory file. 39 | RUN mkdir -p /etc/ansible 40 | RUN echo -e '[local]\nlocalhost ansible_connection=local' > /etc/ansible/hosts 41 | 42 | VOLUME ["/sys/fs/cgroup"] 43 | CMD ["/usr/lib/systemd/systemd"] 44 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Universal Base Image 8 Ansible Test Image 2 | 3 | [![Build Status](https://travis-ci.com/geerlingguy/docker-ubi8-ansible.svg?branch=master)](https://travis-ci.com/geerlingguy/docker-ubi8-ansible) [![Docker Automated build](https://img.shields.io/docker/automated/geerlingguy/docker-ubi8-ansible.svg?maxAge=2592000)](https://hub.docker.com/r/geerlingguy/docker-ubi8-ansible/) 4 | 5 | UBI 8 (base of Red Hat Enterprise Linux 8) Docker container for Ansible playbook and role testing. 6 | 7 | ## Tags 8 | 9 | - `latest`: Latest stable version of Ansible. 10 | - `testing`: Same as `latest`, but with additional testing dependencies, including: 11 | - `yamllint` 12 | - `ansible-lint` 13 | - `flake8` 14 | - `testinfra` 15 | - `molecule` 16 | 17 | The latest tag is a lightweight image for basic validation of Ansible playbooks. The `testing` tag also includes a comprehensive suite of Ansible and infrastructure testing tools in case you want them pre-installed. 18 | 19 | ## How to Build 20 | 21 | 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: 22 | 23 | 1. [Install Docker](https://docs.docker.com/engine/installation/). 24 | 2. `cd` into this directory. 25 | 3. Run `docker build -t ubi8-ansible .` 26 | 27 | > Note: Switch between `master` and `testing` depending on whether you want the extra testing tools present in the resulting image. 28 | 29 | ## How to Use 30 | 31 | 1. [Install Docker](https://docs.docker.com/engine/installation/). 32 | 2. Pull this image from Docker Hub: `docker pull geerlingguy/docker-ubi8-ansible:latest` (or use the image you built earlier, e.g. `ubi8-ansible:latest`). 33 | 3. Run a container from the image: `docker run --detach --privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro geerlingguy/docker-ubi8-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``). 34 | 4. Use Ansible inside the container: 35 | a. `docker exec --tty [container_id] env TERM=xterm ansible --version` 36 | b. `docker exec --tty [container_id] env TERM=xterm ansible-playbook /path/to/ansible/playbook.yml --syntax-check` 37 | 38 | ## Notes 39 | 40 | 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. 41 | 42 | > **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! 43 | 44 | ## Author 45 | 46 | Created in 2019 by [Jeff Geerling](https://www.jeffgeerling.com/), author of [Ansible for DevOps](https://www.ansiblefordevops.com/). 47 | --------------------------------------------------------------------------------