]> git.immae.eu Git - github/fretlink/docker-ansible.git/blame - README.md
Add: building from source tree.
[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
ae06b63d 19- OS: Debian (jessie, wheezy), Ubuntu (trusty, precise), CentOS (7, 6), Alpine (3).
d3c54163 20
930848e7 21- Ansible: usually the most recent *stable* and *experimental* versions (I didn't pin any specific version).
d3c54163
WY
22
23
ebfd2bf2
WY
24## Images and tags
25
930848e7
WY
26### Stable series (installed from official PyPI repo):
27
aa3cb4d5 28- Normal series:
ebfd2bf2
WY
29
30 - `williamyeh/ansible:debian8`
31 - `williamyeh/ansible:debian7`
32 - `williamyeh/ansible:ubuntu14.04`
33 - `williamyeh/ansible:ubuntu12.04`
02c34901 34 - `williamyeh/ansible:centos7`
e6ab6fea 35 - `williamyeh/ansible:centos6`
ae06b63d 36 - `williamyeh/ansible:alpine3`
ebfd2bf2 37
ffe10e81 38- Onbuild series (*recommended for common cases*):
ebfd2bf2
WY
39
40 - `williamyeh/ansible:debian8-onbuild`
41 - `williamyeh/ansible:debian7-onbuild`
42 - `williamyeh/ansible:ubuntu14.04-onbuild`
43 - `williamyeh/ansible:ubuntu12.04-onbuild`
02c34901 44 - `williamyeh/ansible:centos7-onbuild`
e6ab6fea 45 - `williamyeh/ansible:centos6-onbuild`
ae06b63d 46 - `williamyeh/ansible:alpine3-onbuild`
ebfd2bf2 47
930848e7
WY
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
d3c54163 69
c20fa492
WY
70## For the impatient
71
72Here comes a simplest working example for the impatient.
73
74First, choose a base image you'd like to begin with. For example, `williamyeh/ansible:ubuntu14.04-onbuild`.
75
76Second, put the following `Dockerfile` along with your playbook directory:
77
78```
79FROM williamyeh/ansible:ubuntu14.04-onbuild
80
8287be90
WY
81# ==> Specify requirements filename; default = "requirements.yml"
82#ENV REQUIREMENTS requirements.yml
c20fa492 83
8287be90
WY
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
c20fa492 89
ffe10e81 90# ==> Executing Ansible (with a simple wrapper)...
c20fa492
WY
91RUN ansible-playbook-wrapper
92```
93
94Third, `docker build .`
95
96Done!
97
aa3cb4d5 98For 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.
c20fa492
WY
99
100
101
102
d3c54163
WY
103## Why yet another Ansible image for Docker?
104
105There 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
107In 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
113Therefore, I built these Docker images on my own.
114
2fd99bb9 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.”
d3c54163 116
c20fa492
WY
117### Comparison: image size
118
119```
120REPOSITORY TAG VIRTUAL SIZE
121--------------------------- ------------------- ------------
122ansible/centos7-ansible stable 367.5 MB
123ansible/ubuntu14.04-ansible stable 286.6 MB
124
ae06b63d 125williamyeh/ansible alpine3-onbuild 66.4 MB
c20fa492
WY
126williamyeh/ansible centos6-onbuild 264.2 MB
127williamyeh/ansible centos7-onbuild 275.3 MB
128williamyeh/ansible debian7-onbuild 134.4 MB
129williamyeh/ansible debian8-onbuild 178.3 MB
130williamyeh/ansible ubuntu12.04-onbuild 181.9 MB
131williamyeh/ansible ubuntu14.04-onbuild 238.3 MB
132```
133
134
d3c54163
WY
135## Usage
136
aa3cb4d5 137Used mostly as a *base image* for configuring other software stack on some specified Linux distribution(s).
d3c54163 138
c20fa492 139Take 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
140
141```ruby
142# Vagrantfile
143
144Vagrant.configure(2) do |config|
145
146 # ==> Choose a Vagrant box to emulate Linux distribution...
147 config.vm.box = "ubuntu/trusty64"
ae06b63d
WY
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"
e6ab6fea 154
d3c54163
WY
155
156 # ==> Executing Ansible...
157 config.vm.provision "ansible" do |ansible|
158 ansible.playbook = "playbook.yml"
159 end
160
161end
162```
163
ebfd2bf2
WY
164Virtual machines can emulate a variety of Linux distributions with good quality, at the cost of runtime overhead.
165
d3c54163
WY
166
167Docker 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...
174FROM williamyeh/ansible:ubuntu14.04
175#FROM williamyeh/ansible:ubuntu12.04
ebfd2bf2 176#FROM williamyeh/ansible:debian8
d3c54163 177#FROM williamyeh/ansible:debian7
02c34901 178#FROM williamyeh/ansible:centos7
e6ab6fea 179#FROM williamyeh/ansible:centos6
ae06b63d 180#FROM williamyeh/ansible:alpine3
d3c54163 181
ebfd2bf2 182
d3c54163
WY
183# ==> Copying Ansible playbook...
184WORKDIR /tmp
185COPY . /tmp
186
187# ==> Creating inventory file...
188RUN echo localhost > inventory
189
190# ==> Executing Ansible...
191RUN ansible-playbook -i inventory playbook.yml \
192 --connection=local --sudo
193```
194
ffe10e81 195You may also work with `onbuild` series, which take care of many routine steps for you:
ebfd2bf2
WY
196
197```dockerfile
198# Dockerfile
199
200# ==> Choose a base image to emulate Linux distribution...
201FROM williamyeh/ansible:ubuntu14.04-onbuild
202#FROM williamyeh/ansible:ubuntu12.04-onbuild
203#FROM williamyeh/ansible:debian8-onbuild
204#FROM williamyeh/ansible:debian7-onbuild
02c34901 205#FROM williamyeh/ansible:centos7-onbuild
e6ab6fea 206#FROM williamyeh/ansible:centos6-onbuild
ae06b63d 207#FROM williamyeh/ansible:alpine3-onbuild
ebfd2bf2
WY
208
209
8287be90
WY
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
ebfd2bf2 215
8287be90
WY
216# ==> Specify inventory filename; default = "/etc/ansible/hosts"
217#ENV INVENTORY inventory.ini
ebfd2bf2 218
ffe10e81 219# ==> Executing Ansible (with a simple wrapper)...
ebfd2bf2
WY
220RUN ansible-playbook-wrapper
221```
222
223
224
d3c54163
WY
225With 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
ebfd2bf2
WY
227If better OS emulation (virtualization) isn't required, the Docker approach (containerization) should give you a more efficient Ansible experience.
228
d3c54163
WY
229
230
231## License
232
233Author: William Yeh <william.pjyeh@gmail.com>
234
235Licensed under the Apache License V2.0. See the [LICENSE file](LICENSE) for details.