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