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