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