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