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