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