]> git.immae.eu Git - github/fretlink/docker-ansible.git/blame - README.md
Add: Windows managed node support via "pywinrm".
[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
b1f3718d 9Repository name in Docker Hub: **[williamyeh/ansible](https://hub.docker.com/r/williamyeh/ansible/)**
d3c54163 10
b1f3718d 11This repository contains Dockerized [Ansible](https://github.com/ansible/ansible), published to the public [Docker Hub](https://hub.docker.com/) via **automated build** mechanism.
d3c54163
WY
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
57d366d7 19### Base OS
d3c54163 20
57d366d7
WY
21Debian (jessie), Ubuntu (xenial, trusty), CentOS (7), Alpine (3).
22
23Supports for Wheezy, Precise, and CentOS6 have been ended since Sep 2017.
24
25### Ansible
26
27Four versions are provided:
14e54a03 28
13375974 29 1. provides the most recent *stable* version of Ansible; suitable for most people.
7d885c87 30 2. same as stable version, but is designed for building (near-)*minimal* images out of playbooks; i.e., the Ansible body will be removed when mission completed. Refer to “[Build Docker images with Ansible: A half-blood approach](https://github.com/William-Yeh/build-docker-with-ansible)” for working examples and slides.
57d366d7
WY
31 3. provides the old 1.9 version of Ansible (but will be retired someday).
32 4. provides the *experimental* version of Ansible; i.e., the master branch of official [Ansible's git repo](https://github.com/ansible/ansible).
b1f3718d 33
b1f3718d
WY
34Each version is further divided into two variants:
35
7d885c87
WY
36- *Normal* variant: intended to be used as Ansible *control machines*, or in cases that is inadequate in the onbuild variants.
37- *Onbuild* variant: intended to be used to build Docker images.
d3c54163
WY
38
39
ebfd2bf2
WY
40## Images and tags
41
de4433f3 42### Stable version (installed from official PyPI repo):
930848e7 43
b1f3718d 44- Normal variants:
ebfd2bf2
WY
45
46 - `williamyeh/ansible:debian8`
97d48efe 47 - `williamyeh/ansible:ubuntu16.04`
ebfd2bf2 48 - `williamyeh/ansible:ubuntu14.04`
02c34901 49 - `williamyeh/ansible:centos7`
ae06b63d 50 - `williamyeh/ansible:alpine3`
ebfd2bf2 51
b1f3718d 52- Onbuild variants (*recommended for common cases*):
ebfd2bf2
WY
53
54 - `williamyeh/ansible:debian8-onbuild`
97d48efe 55 - `williamyeh/ansible:ubuntu16.04-onbuild`
ebfd2bf2 56 - `williamyeh/ansible:ubuntu14.04-onbuild`
02c34901 57 - `williamyeh/ansible:centos7-onbuild`
ae06b63d 58 - `williamyeh/ansible:alpine3-onbuild`
ebfd2bf2 59
13375974
WY
60
61### Minimal configuration (the Ansible body will be removed when mission completed):
62
7d885c87
WY
63Refer to “[Build Docker images with Ansible: A half-blood approach](https://github.com/William-Yeh/build-docker-with-ansible)” for working examples and slides.
64
b1f3718d 65- Onbuild variants:
13375974
WY
66
67 - `williamyeh/ansible:mini-alpine3`
68 - `williamyeh/ansible:mini-debian8`
69
70
57d366d7
WY
71### Old 1.9 version (will be retired someday):
72
73Note: Ansible 1.9 was not supported in CentOS EPEL since January 2017, according to [this announcement](http://www.spinics.net/linux/fedora/epel-devel/msg00792.html).
14e54a03 74
b1f3718d 75- Normal variants:
14e54a03
WY
76
77 - `williamyeh/ansible:1.9-debian8`
14e54a03 78 - `williamyeh/ansible:1.9-ubuntu14.04`
14e54a03
WY
79 - `williamyeh/ansible:1.9-alpine3`
80
b1f3718d 81- Onbuild variants (*recommended for common cases*):
14e54a03
WY
82
83 - `williamyeh/ansible:1.9-debian8-onbuild`
14e54a03 84 - `williamyeh/ansible:1.9-ubuntu14.04-onbuild`
14e54a03
WY
85 - `williamyeh/ansible:1.9-alpine3-onbuild`
86
13375974 87
de4433f3 88### Experimental version (building directly from the git `master` source tree; use at your own risk!):
930848e7 89
b1f3718d 90- Normal variants:
930848e7
WY
91
92 - `williamyeh/ansible:master-debian8`
97d48efe 93 - `williamyeh/ansible:master-ubuntu16.04`
930848e7 94 - `williamyeh/ansible:master-ubuntu14.04`
930848e7 95 - `williamyeh/ansible:master-centos7`
930848e7 96
b1f3718d 97- Onbuild variants (*recommended for common cases*):
930848e7
WY
98
99 - `williamyeh/ansible:master-debian8-onbuild`
97d48efe 100 - `williamyeh/ansible:master-ubuntu16.04-onbuild`
930848e7 101 - `williamyeh/ansible:master-ubuntu14.04-onbuild`
930848e7 102 - `williamyeh/ansible:master-centos7-onbuild`
930848e7
WY
103
104
d3c54163 105
c20fa492
WY
106## For the impatient
107
108Here comes a simplest working example for the impatient.
109
110First, choose a base image you'd like to begin with. For example, `williamyeh/ansible:ubuntu14.04-onbuild`.
111
112Second, put the following `Dockerfile` along with your playbook directory:
113
114```
115FROM williamyeh/ansible:ubuntu14.04-onbuild
116
8287be90
WY
117# ==> Specify requirements filename; default = "requirements.yml"
118#ENV REQUIREMENTS requirements.yml
c20fa492 119
8287be90
WY
120# ==> Specify playbook filename; default = "playbook.yml"
121#ENV PLAYBOOK playbook.yml
122
123# ==> Specify inventory filename; default = "/etc/ansible/hosts"
124#ENV INVENTORY inventory.ini
c20fa492 125
ffe10e81 126# ==> Executing Ansible (with a simple wrapper)...
c20fa492
WY
127RUN ansible-playbook-wrapper
128```
129
130Third, `docker build .`
131
132Done!
133
97d48efe 134For 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
135
136
137
138
d3c54163
WY
139## Why yet another Ansible image for Docker?
140
b1f3718d 141There has been quite a few Ansible images for Docker (e.g., [search](https://hub.docker.com/search/?q=ansible&isAutomated=0&isOfficial=0&page=1&pullCount=1&starCount=0) in the Docker Hub), so why reinvent the wheel?
d3c54163
WY
142
143In 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:
144
145- *Base OS image* - It provides only `centos:centos7` and `ubuntu:14.04`. Insufficent for me.
146
147- *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.
148
149Therefore, I built these Docker images on my own.
150
2fd99bb9 151**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 152
c20fa492
WY
153### Comparison: image size
154
155```
156REPOSITORY TAG VIRTUAL SIZE
157--------------------------- ------------------- ------------
158ansible/centos7-ansible stable 367.5 MB
159ansible/ubuntu14.04-ansible stable 286.6 MB
160
ae06b63d 161williamyeh/ansible alpine3-onbuild 66.4 MB
c20fa492
WY
162williamyeh/ansible centos6-onbuild 264.2 MB
163williamyeh/ansible centos7-onbuild 275.3 MB
164williamyeh/ansible debian7-onbuild 134.4 MB
165williamyeh/ansible debian8-onbuild 178.3 MB
166williamyeh/ansible ubuntu12.04-onbuild 181.9 MB
167williamyeh/ansible ubuntu14.04-onbuild 238.3 MB
168```
169
170
d3c54163
WY
171## Usage
172
aa3cb4d5 173Used mostly as a *base image* for configuring other software stack on some specified Linux distribution(s).
d3c54163 174
c20fa492 175Take 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
176
177```ruby
178# Vagrantfile
179
180Vagrant.configure(2) do |config|
181
182 # ==> Choose a Vagrant box to emulate Linux distribution...
97d48efe 183 #config.vm.box = "ubuntu/xenial64"
d3c54163 184 config.vm.box = "ubuntu/trusty64"
ae06b63d 185 #config.vm.box = "debian/jessie64"
de4433f3 186 #config.vm.box = "bento/centos-7.2"
de4433f3 187 #config.vm.box = "maier/alpine-3.3.1-x86_64"
e6ab6fea 188
d3c54163
WY
189
190 # ==> Executing Ansible...
191 config.vm.provision "ansible" do |ansible|
192 ansible.playbook = "playbook.yml"
193 end
194
195end
196```
197
ebfd2bf2
WY
198Virtual machines can emulate a variety of Linux distributions with good quality, at the cost of runtime overhead.
199
d3c54163
WY
200
201Docker 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:
202
203
204```dockerfile
205# Dockerfile
206
207# ==> Choose a base image to emulate Linux distribution...
97d48efe 208#FROM williamyeh/ansible:ubuntu16.04
d3c54163 209FROM williamyeh/ansible:ubuntu14.04
ebfd2bf2 210#FROM williamyeh/ansible:debian8
02c34901 211#FROM williamyeh/ansible:centos7
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
b1f3718d 227You may also work with `onbuild` variants, 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 234FROM williamyeh/ansible:ubuntu14.04-onbuild
ebfd2bf2 235#FROM williamyeh/ansible:debian8-onbuild
02c34901 236#FROM williamyeh/ansible:centos7-onbuild
ae06b63d 237#FROM williamyeh/ansible:alpine3-onbuild
ebfd2bf2
WY
238
239
8287be90
WY
240# ==> Specify requirements filename; default = "requirements.yml"
241#ENV REQUIREMENTS requirements.yml
242
243# ==> Specify playbook filename; default = "playbook.yml"
244#ENV PLAYBOOK playbook.yml
ebfd2bf2 245
8287be90
WY
246# ==> Specify inventory filename; default = "/etc/ansible/hosts"
247#ENV INVENTORY inventory.ini
ebfd2bf2 248
ffe10e81 249# ==> Executing Ansible (with a simple wrapper)...
ebfd2bf2
WY
250RUN ansible-playbook-wrapper
251```
252
253
254
d3c54163
WY
255With 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!
256
ebfd2bf2
WY
257If better OS emulation (virtualization) isn't required, the Docker approach (containerization) should give you a more efficient Ansible experience.
258
d3c54163
WY
259
260
261## License
262
263Author: William Yeh <william.pjyeh@gmail.com>
264
265Licensed under the Apache License V2.0. See the [LICENSE file](LICENSE) for details.