1 Docker-Ansible base images
4 [![Circle CI](https://circleci.com/gh/William-Yeh/docker-ansible.svg?style=shield)](https://circleci.com/gh/William-Yeh/docker-ansible) [![Build Status](https://travis-ci.org/William-Yeh/docker-ansible.svg?branch=master)](https://travis-ci.org/William-Yeh/docker-ansible)
9 Repository name in Docker Hub: **[williamyeh/ansible](https://registry.hub.docker.com/u/williamyeh/ansible/)**
11 This repository contains Dockerized [Ansible](https://github.com/ansible/ansible), published to the public [Docker Hub](https://registry.hub.docker.com/) via **automated build** mechanism.
17 These are Docker images for [Ansible](https://github.com/ansible/ansible) software, installed in a selected Linux distributions.
19 - OS: Debian (jessie, wheezy), Ubuntu (trusty, precise), CentOS (7, 6), Alpine (3).
21 - Ansible: usually the most recent *stable* and *experimental* versions (I didn't pin any specific version).
26 ### Stable version (installed from official PyPI repo):
30 - `williamyeh/ansible:debian8`
31 - `williamyeh/ansible:debian7`
32 - `williamyeh/ansible:ubuntu14.04`
33 - `williamyeh/ansible:ubuntu12.04`
34 - `williamyeh/ansible:centos7`
35 - `williamyeh/ansible:centos6`
36 - `williamyeh/ansible:alpine3`
38 - Onbuild series (*recommended for common cases*):
40 - `williamyeh/ansible:debian8-onbuild`
41 - `williamyeh/ansible:debian7-onbuild`
42 - `williamyeh/ansible:ubuntu14.04-onbuild`
43 - `williamyeh/ansible:ubuntu12.04-onbuild`
44 - `williamyeh/ansible:centos7-onbuild`
45 - `williamyeh/ansible:centos6-onbuild`
46 - `williamyeh/ansible:alpine3-onbuild`
48 ### Experimental version (building directly from the git `master` source tree; use at your own risk!):
52 - `williamyeh/ansible:master-debian8`
53 - `williamyeh/ansible:master-debian7`
54 - `williamyeh/ansible:master-ubuntu14.04`
55 - `williamyeh/ansible:master-ubuntu12.04`
56 - `williamyeh/ansible:master-centos7`
57 - `williamyeh/ansible:master-centos6`
59 - Onbuild series (*recommended for common cases*):
61 - `williamyeh/ansible:master-debian8-onbuild`
62 - `williamyeh/ansible:master-debian7-onbuild`
63 - `williamyeh/ansible:master-ubuntu14.04-onbuild`
64 - `williamyeh/ansible:master-ubuntu12.04-onbuild`
65 - `williamyeh/ansible:master-centos7-onbuild`
66 - `williamyeh/ansible:master-centos6-onbuild`
72 Here comes a simplest working example for the impatient.
74 First, choose a base image you'd like to begin with. For example, `williamyeh/ansible:ubuntu14.04-onbuild`.
76 Second, put the following `Dockerfile` along with your playbook directory:
79 FROM williamyeh/ansible:ubuntu14.04-onbuild
81 # ==> Specify requirements filename; default = "requirements.yml"
82 #ENV REQUIREMENTS requirements.yml
84 # ==> Specify playbook filename; default = "playbook.yml"
85 #ENV PLAYBOOK playbook.yml
87 # ==> Specify inventory filename; default = "/etc/ansible/hosts"
88 #ENV INVENTORY inventory.ini
90 # ==> Executing Ansible (with a simple wrapper)...
91 RUN ansible-playbook-wrapper
94 Third, `docker build .`
98 For more advanced usage, the role in Ansible Galaxy [`williamyeh/nginx`](https://galaxy.ansible.com/williamyeh/nginx/) demonstrates how to perform a simple smoke test (*configuration needs test, too!*) on a variety of (*containerized*) Linux distributions via [CircleCI](https://circleci.com/)'s Ubuntu 12.04 and [Travis CI](https://travis-ci.org/)’s Ubuntu 14.04 worker instances.
103 ## Why yet another Ansible image for Docker?
105 There has been quite a few Ansible images for Docker (e.g., [search](https://registry.hub.docker.com/search?q=ansible) in the Docker Hub), so why reinvent the wheel?
107 In the beginning I used the [`ansible/ansible-docker-base`](https://github.com/ansible/ansible-docker-base) created by Ansible Inc. It worked well, but left some room for improvement:
109 - *Base OS image* - It provides only `centos:centos7` and `ubuntu:14.04`. Insufficent for me.
111 - *Unnecessary dependencies* - It installed, at the very beginning of its Dockerfile, the `software-properties-common` package, which in turns installed some Python packages. I prefered to incorporate these stuff only when absolutely needed.
113 Therefore, I built these Docker images on my own.
115 **NOTE:** [`ansible/ansible-docker-base`](https://github.com/ansible/ansible-docker-base) announced in September 2015: “Ansible no longer maintains images in Dockerhub directly.”
117 ### Comparison: image size
120 REPOSITORY TAG VIRTUAL SIZE
121 --------------------------- ------------------- ------------
122 ansible/centos7-ansible stable 367.5 MB
123 ansible/ubuntu14.04-ansible stable 286.6 MB
125 williamyeh/ansible alpine3-onbuild 66.4 MB
126 williamyeh/ansible centos6-onbuild 264.2 MB
127 williamyeh/ansible centos7-onbuild 275.3 MB
128 williamyeh/ansible debian7-onbuild 134.4 MB
129 williamyeh/ansible debian8-onbuild 178.3 MB
130 williamyeh/ansible ubuntu12.04-onbuild 181.9 MB
131 williamyeh/ansible ubuntu14.04-onbuild 238.3 MB
137 Used mostly as a *base image* for configuring other software stack on some specified Linux distribution(s).
139 Take Debian/Ubuntu/CentOS for example. To test an Ansible `playbook.yml` against a variety of Linux distributions, we may use [Vagrant](https://www.vagrantup.com/) as follows:
144 Vagrant.configure(2) do |config|
146 # ==> Choose a Vagrant box to emulate Linux distribution...
147 config.vm.box = "ubuntu/trusty64"
148 #config.vm.box = "ubuntu/precise64"
149 #config.vm.box = "debian/jessie64"
150 #config.vm.box = "debian/wheezy64"
151 #config.vm.box = "bento/centos-7.2"
152 #config.vm.box = "bento/centos-6.7"
153 #config.vm.box = "maier/alpine-3.3.1-x86_64"
156 # ==> Executing Ansible...
157 config.vm.provision "ansible" do |ansible|
158 ansible.playbook = "playbook.yml"
164 Virtual machines can emulate a variety of Linux distributions with good quality, at the cost of runtime overhead.
167 Docker to be a rescue. Now, with these **williamyeh/ansible** series, we may test an Ansible `playbook.yml` against a variety of Linux distributions as follows:
173 # ==> Choose a base image to emulate Linux distribution...
174 FROM williamyeh/ansible:ubuntu14.04
175 #FROM williamyeh/ansible:ubuntu12.04
176 #FROM williamyeh/ansible:debian8
177 #FROM williamyeh/ansible:debian7
178 #FROM williamyeh/ansible:centos7
179 #FROM williamyeh/ansible:centos6
180 #FROM williamyeh/ansible:alpine3
183 # ==> Copying Ansible playbook...
187 # ==> Creating inventory file...
188 RUN echo localhost > inventory
190 # ==> Executing Ansible...
191 RUN ansible-playbook -i inventory playbook.yml \
192 --connection=local --sudo
195 You may also work with `onbuild` series, which take care of many routine steps for you:
200 # ==> Choose a base image to emulate Linux distribution...
201 FROM williamyeh/ansible:ubuntu14.04-onbuild
202 #FROM williamyeh/ansible:ubuntu12.04-onbuild
203 #FROM williamyeh/ansible:debian8-onbuild
204 #FROM williamyeh/ansible:debian7-onbuild
205 #FROM williamyeh/ansible:centos7-onbuild
206 #FROM williamyeh/ansible:centos6-onbuild
207 #FROM williamyeh/ansible:alpine3-onbuild
210 # ==> Specify requirements filename; default = "requirements.yml"
211 #ENV REQUIREMENTS requirements.yml
213 # ==> Specify playbook filename; default = "playbook.yml"
214 #ENV PLAYBOOK playbook.yml
216 # ==> Specify inventory filename; default = "/etc/ansible/hosts"
217 #ENV INVENTORY inventory.ini
219 # ==> Executing Ansible (with a simple wrapper)...
220 RUN ansible-playbook-wrapper
225 With Docker, we can test any Ansible playbook against any version of any Linux distribution without the help of Vagrant. More lightweight, and more portable across IaaS, PaaS, and even CaaS (Container as a Service) providers!
227 If better OS emulation (virtualization) isn't required, the Docker approach (containerization) should give you a more efficient Ansible experience.
233 Author: William Yeh <william.pjyeh@gmail.com>
235 Licensed under the Apache License V2.0. See the [LICENSE file](LICENSE) for details.