]> git.immae.eu Git - github/fretlink/docker-ansible.git/blame - README.md
Add: new `mini` series for building minimal images from playbooks.
[github/fretlink/docker-ansible.git] / README.md
CommitLineData
d3c54163
WY
1Docker-Ansible base images
2===================
3
eb32e88f 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)
02c34901 5
d3c54163
WY
6
7## Summary
8
9a0d65e4 9Repository name in Docker Hub: **[williamyeh/ansible](https://registry.hub.docker.com/u/williamyeh/ansible/)**
d3c54163
WY
10
11This repository contains Dockerized [Ansible](https://github.com/ansible/ansible), published to the public [Docker Hub](https://registry.hub.docker.com/) via **automated build** mechanism.
12
13
14
15## Configuration
16
17These are Docker images for [Ansible](https://github.com/ansible/ansible) software, installed in a selected Linux distributions.
18
97d48efe 19- OS: Debian (jessie, wheezy), Ubuntu (xenial, trusty, precise), CentOS (7, 6), Alpine (3).
d3c54163 20
f9662428 21- Ansible: four series -
14e54a03
WY
22
23 1. the most recent *stable* version;
24 2. old 1.9 version;
f9662428
WY
25 3. the *experimental* version;
26 4. for building *minimal* images from playbooks; i.e., the Ansible body will be removed when mission completed.
d3c54163
WY
27
28
ebfd2bf2
WY
29## Images and tags
30
de4433f3 31### Stable version (installed from official PyPI repo):
930848e7 32
aa3cb4d5 33- Normal series:
ebfd2bf2
WY
34
35 - `williamyeh/ansible:debian8`
36 - `williamyeh/ansible:debian7`
97d48efe 37 - `williamyeh/ansible:ubuntu16.04`
ebfd2bf2
WY
38 - `williamyeh/ansible:ubuntu14.04`
39 - `williamyeh/ansible:ubuntu12.04`
02c34901 40 - `williamyeh/ansible:centos7`
e6ab6fea 41 - `williamyeh/ansible:centos6`
ae06b63d 42 - `williamyeh/ansible:alpine3`
ebfd2bf2 43
ffe10e81 44- Onbuild series (*recommended for common cases*):
ebfd2bf2
WY
45
46 - `williamyeh/ansible:debian8-onbuild`
47 - `williamyeh/ansible:debian7-onbuild`
97d48efe 48 - `williamyeh/ansible:ubuntu16.04-onbuild`
ebfd2bf2
WY
49 - `williamyeh/ansible:ubuntu14.04-onbuild`
50 - `williamyeh/ansible:ubuntu12.04-onbuild`
02c34901 51 - `williamyeh/ansible:centos7-onbuild`
e6ab6fea 52 - `williamyeh/ansible:centos6-onbuild`
ae06b63d 53 - `williamyeh/ansible:alpine3-onbuild`
ebfd2bf2 54
14e54a03
WY
55### Old 1.9 version:
56
57- Normal series:
58
59 - `williamyeh/ansible:1.9-debian8`
60 - `williamyeh/ansible:1.9-debian7`
61 - `williamyeh/ansible:1.9-ubuntu14.04`
62 - `williamyeh/ansible:1.9-ubuntu12.04`
63 - `williamyeh/ansible:1.9-centos7`
64 - `williamyeh/ansible:1.9-centos6`
65 - `williamyeh/ansible:1.9-alpine3`
66
67- Onbuild series (*recommended for common cases*):
68
69 - `williamyeh/ansible:1.9-debian8-onbuild`
70 - `williamyeh/ansible:1.9-debian7-onbuild`
71 - `williamyeh/ansible:1.9-ubuntu14.04-onbuild`
72 - `williamyeh/ansible:1.9-ubuntu12.04-onbuild`
73 - `williamyeh/ansible:1.9-centos7-onbuild`
74 - `williamyeh/ansible:1.9-centos6-onbuild`
75 - `williamyeh/ansible:1.9-alpine3-onbuild`
76
de4433f3 77### Experimental version (building directly from the git `master` source tree; use at your own risk!):
930848e7
WY
78
79- Normal series:
80
81 - `williamyeh/ansible:master-debian8`
82 - `williamyeh/ansible:master-debian7`
97d48efe 83 - `williamyeh/ansible:master-ubuntu16.04`
930848e7
WY
84 - `williamyeh/ansible:master-ubuntu14.04`
85 - `williamyeh/ansible:master-ubuntu12.04`
86 - `williamyeh/ansible:master-centos7`
87 - `williamyeh/ansible:master-centos6`
88
89- Onbuild series (*recommended for common cases*):
90
91 - `williamyeh/ansible:master-debian8-onbuild`
92 - `williamyeh/ansible:master-debian7-onbuild`
97d48efe 93 - `williamyeh/ansible:master-ubuntu16.04-onbuild`
930848e7
WY
94 - `williamyeh/ansible:master-ubuntu14.04-onbuild`
95 - `williamyeh/ansible:master-ubuntu12.04-onbuild`
96 - `williamyeh/ansible:master-centos7-onbuild`
97 - `williamyeh/ansible:master-centos6-onbuild`
98
99
f9662428
WY
100### Minimal series (the Ansible body will be removed when mission completed):
101
102- Onbuild series:
103
104 - `williamyeh/ansible:mini-alpine3`
105
106
d3c54163 107
c20fa492
WY
108## For the impatient
109
110Here comes a simplest working example for the impatient.
111
112First, choose a base image you'd like to begin with. For example, `williamyeh/ansible:ubuntu14.04-onbuild`.
113
114Second, put the following `Dockerfile` along with your playbook directory:
115
116```
117FROM williamyeh/ansible:ubuntu14.04-onbuild
118
8287be90
WY
119# ==> Specify requirements filename; default = "requirements.yml"
120#ENV REQUIREMENTS requirements.yml
c20fa492 121
8287be90
WY
122# ==> Specify playbook filename; default = "playbook.yml"
123#ENV PLAYBOOK playbook.yml
124
125# ==> Specify inventory filename; default = "/etc/ansible/hosts"
126#ENV INVENTORY inventory.ini
c20fa492 127
ffe10e81 128# ==> Executing Ansible (with a simple wrapper)...
c20fa492
WY
129RUN ansible-playbook-wrapper
130```
131
132Third, `docker build .`
133
134Done!
135
97d48efe 136For 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 on [CircleCI](https://circleci.com/)'s Ubuntu 12.04 and [Travis CI](https://travis-ci.org/)’s Ubuntu 14.04 worker instances.
c20fa492
WY
137
138
139
140
d3c54163
WY
141## Why yet another Ansible image for Docker?
142
143There 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?
144
145In 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:
146
147- *Base OS image* - It provides only `centos:centos7` and `ubuntu:14.04`. Insufficent for me.
148
149- *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.
150
151Therefore, I built these Docker images on my own.
152
2fd99bb9 153**NOTE:** [`ansible/ansible-docker-base`](https://github.com/ansible/ansible-docker-base) announced in September 2015: “Ansible no longer maintains images in Dockerhub directly.”
d3c54163 154
c20fa492
WY
155### Comparison: image size
156
157```
158REPOSITORY TAG VIRTUAL SIZE
159--------------------------- ------------------- ------------
160ansible/centos7-ansible stable 367.5 MB
161ansible/ubuntu14.04-ansible stable 286.6 MB
162
ae06b63d 163williamyeh/ansible alpine3-onbuild 66.4 MB
c20fa492
WY
164williamyeh/ansible centos6-onbuild 264.2 MB
165williamyeh/ansible centos7-onbuild 275.3 MB
166williamyeh/ansible debian7-onbuild 134.4 MB
167williamyeh/ansible debian8-onbuild 178.3 MB
168williamyeh/ansible ubuntu12.04-onbuild 181.9 MB
169williamyeh/ansible ubuntu14.04-onbuild 238.3 MB
170```
171
172
d3c54163
WY
173## Usage
174
aa3cb4d5 175Used mostly as a *base image* for configuring other software stack on some specified Linux distribution(s).
d3c54163 176
c20fa492 177Take 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:
d3c54163
WY
178
179```ruby
180# Vagrantfile
181
182Vagrant.configure(2) do |config|
183
184 # ==> Choose a Vagrant box to emulate Linux distribution...
97d48efe 185 #config.vm.box = "ubuntu/xenial64"
d3c54163 186 config.vm.box = "ubuntu/trusty64"
ae06b63d
WY
187 #config.vm.box = "ubuntu/precise64"
188 #config.vm.box = "debian/jessie64"
189 #config.vm.box = "debian/wheezy64"
de4433f3 190 #config.vm.box = "bento/centos-7.2"
ae06b63d 191 #config.vm.box = "bento/centos-6.7"
de4433f3 192 #config.vm.box = "maier/alpine-3.3.1-x86_64"
e6ab6fea 193
d3c54163
WY
194
195 # ==> Executing Ansible...
196 config.vm.provision "ansible" do |ansible|
197 ansible.playbook = "playbook.yml"
198 end
199
200end
201```
202
ebfd2bf2
WY
203Virtual machines can emulate a variety of Linux distributions with good quality, at the cost of runtime overhead.
204
d3c54163
WY
205
206Docker 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:
207
208
209```dockerfile
210# Dockerfile
211
212# ==> Choose a base image to emulate Linux distribution...
97d48efe 213#FROM williamyeh/ansible:ubuntu16.04
d3c54163
WY
214FROM williamyeh/ansible:ubuntu14.04
215#FROM williamyeh/ansible:ubuntu12.04
ebfd2bf2 216#FROM williamyeh/ansible:debian8
d3c54163 217#FROM williamyeh/ansible:debian7
02c34901 218#FROM williamyeh/ansible:centos7
e6ab6fea 219#FROM williamyeh/ansible:centos6
ae06b63d 220#FROM williamyeh/ansible:alpine3
d3c54163 221
ebfd2bf2 222
d3c54163
WY
223# ==> Copying Ansible playbook...
224WORKDIR /tmp
225COPY . /tmp
226
227# ==> Creating inventory file...
228RUN echo localhost > inventory
229
230# ==> Executing Ansible...
231RUN ansible-playbook -i inventory playbook.yml \
232 --connection=local --sudo
233```
234
ffe10e81 235You may also work with `onbuild` series, which take care of many routine steps for you:
ebfd2bf2
WY
236
237```dockerfile
238# Dockerfile
239
240# ==> Choose a base image to emulate Linux distribution...
97d48efe 241#FROM williamyeh/ansible:ubuntu16.04-onbuild
ebfd2bf2
WY
242FROM williamyeh/ansible:ubuntu14.04-onbuild
243#FROM williamyeh/ansible:ubuntu12.04-onbuild
244#FROM williamyeh/ansible:debian8-onbuild
245#FROM williamyeh/ansible:debian7-onbuild
02c34901 246#FROM williamyeh/ansible:centos7-onbuild
e6ab6fea 247#FROM williamyeh/ansible:centos6-onbuild
ae06b63d 248#FROM williamyeh/ansible:alpine3-onbuild
ebfd2bf2
WY
249
250
8287be90
WY
251# ==> Specify requirements filename; default = "requirements.yml"
252#ENV REQUIREMENTS requirements.yml
253
254# ==> Specify playbook filename; default = "playbook.yml"
255#ENV PLAYBOOK playbook.yml
ebfd2bf2 256
8287be90
WY
257# ==> Specify inventory filename; default = "/etc/ansible/hosts"
258#ENV INVENTORY inventory.ini
ebfd2bf2 259
ffe10e81 260# ==> Executing Ansible (with a simple wrapper)...
ebfd2bf2
WY
261RUN ansible-playbook-wrapper
262```
263
264
265
d3c54163
WY
266With 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!
267
ebfd2bf2
WY
268If better OS emulation (virtualization) isn't required, the Docker approach (containerization) should give you a more efficient Ansible experience.
269
d3c54163
WY
270
271
272## License
273
274Author: William Yeh <william.pjyeh@gmail.com>
275
276Licensed under the Apache License V2.0. See the [LICENSE file](LICENSE) for details.