]> git.immae.eu Git - github/fretlink/docker-ansible.git/blame - README.md
Add: remark about `ansible/ansible-docker-base` statement: “Ansible no longer maintai...
[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
02c34901 19- OS: Debian (jessie, wheezy), Ubuntu (trusty, precise), CentOS (7, 6)
d3c54163
WY
20
21- Ansible: usually the latest version.
22
23
ebfd2bf2
WY
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`
02c34901 32 - `williamyeh/ansible:centos7`
e6ab6fea 33 - `williamyeh/ansible:centos6`
ebfd2bf2
WY
34
35- onbuild series:
36
37 - `williamyeh/ansible:debian8-onbuild`
38 - `williamyeh/ansible:debian7-onbuild`
39 - `williamyeh/ansible:ubuntu14.04-onbuild`
40 - `williamyeh/ansible:ubuntu12.04-onbuild`
02c34901 41 - `williamyeh/ansible:centos7-onbuild`
e6ab6fea 42 - `williamyeh/ansible:centos6-onbuild`
ebfd2bf2 43
d3c54163 44
c20fa492
WY
45## For the impatient
46
47Here comes a simplest working example for the impatient.
48
49First, choose a base image you'd like to begin with. For example, `williamyeh/ansible:ubuntu14.04-onbuild`.
50
51Second, put the following `Dockerfile` along with your playbook directory:
52
53```
54FROM williamyeh/ansible:ubuntu14.04-onbuild
55
8287be90
WY
56# ==> Specify requirements filename; default = "requirements.yml"
57#ENV REQUIREMENTS requirements.yml
c20fa492 58
8287be90
WY
59# ==> Specify playbook filename; default = "playbook.yml"
60#ENV PLAYBOOK playbook.yml
61
62# ==> Specify inventory filename; default = "/etc/ansible/hosts"
63#ENV INVENTORY inventory.ini
c20fa492
WY
64
65# ==> Executing Ansible...
66RUN ansible-playbook-wrapper
67```
68
69Third, `docker build .`
70
71Done!
72
8287be90 73For more advanced usage, the role in Ansible Galaxy [`williamyeh/nginx`](https://galaxy.ansible.com/list#/roles/2245) also demonstrates how to do a simple integration test for a variety of Linux distributions on [CircleCI](https://circleci.com/)'s and [Travis CI](https://travis-ci.org/)’s Ubuntu 12.04 worker instances.
c20fa492
WY
74
75
76
77
d3c54163
WY
78## Why yet another Ansible image for Docker?
79
80There 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?
81
82In 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:
83
84- *Base OS image* - It provides only `centos:centos7` and `ubuntu:14.04`. Insufficent for me.
85
86- *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.
87
88Therefore, I built these Docker images on my own.
89
2fd99bb9 90**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 91
c20fa492
WY
92### Comparison: image size
93
94```
95REPOSITORY TAG VIRTUAL SIZE
96--------------------------- ------------------- ------------
97ansible/centos7-ansible stable 367.5 MB
98ansible/ubuntu14.04-ansible stable 286.6 MB
99
100williamyeh/ansible centos6-onbuild 264.2 MB
101williamyeh/ansible centos7-onbuild 275.3 MB
102williamyeh/ansible debian7-onbuild 134.4 MB
103williamyeh/ansible debian8-onbuild 178.3 MB
104williamyeh/ansible ubuntu12.04-onbuild 181.9 MB
105williamyeh/ansible ubuntu14.04-onbuild 238.3 MB
106```
107
108
d3c54163
WY
109## Usage
110
111Used mostly as a *base image* for configuring, with Ansible, other software stack on some specified Linux distribution.
112
c20fa492 113Take 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
114
115```ruby
116# Vagrantfile
117
118Vagrant.configure(2) do |config|
119
120 # ==> Choose a Vagrant box to emulate Linux distribution...
121 config.vm.box = "ubuntu/trusty64"
122 #config.vm.box = "hashicorp/precise64"
123 #config.vm.box = "chef/debian-7.8"
02c34901 124 #config.vm.box = "chef/centos-7.0"
e6ab6fea
WY
125 #config.vm.box = "chef/centos-6.6"
126
d3c54163
WY
127
128 # ==> Executing Ansible...
129 config.vm.provision "ansible" do |ansible|
130 ansible.playbook = "playbook.yml"
131 end
132
133end
134```
135
ebfd2bf2
WY
136Virtual machines can emulate a variety of Linux distributions with good quality, at the cost of runtime overhead.
137
d3c54163
WY
138
139Docker 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:
140
141
142```dockerfile
143# Dockerfile
144
145# ==> Choose a base image to emulate Linux distribution...
146FROM williamyeh/ansible:ubuntu14.04
147#FROM williamyeh/ansible:ubuntu12.04
ebfd2bf2 148#FROM williamyeh/ansible:debian8
d3c54163 149#FROM williamyeh/ansible:debian7
02c34901 150#FROM williamyeh/ansible:centos7
e6ab6fea 151#FROM williamyeh/ansible:centos6
d3c54163 152
ebfd2bf2 153
d3c54163
WY
154# ==> Copying Ansible playbook...
155WORKDIR /tmp
156COPY . /tmp
157
158# ==> Creating inventory file...
159RUN echo localhost > inventory
160
161# ==> Executing Ansible...
162RUN ansible-playbook -i inventory playbook.yml \
163 --connection=local --sudo
164```
165
ebfd2bf2
WY
166Or, more simple with `onbuild` series:
167
168```dockerfile
169# Dockerfile
170
171# ==> Choose a base image to emulate Linux distribution...
172FROM williamyeh/ansible:ubuntu14.04-onbuild
173#FROM williamyeh/ansible:ubuntu12.04-onbuild
174#FROM williamyeh/ansible:debian8-onbuild
175#FROM williamyeh/ansible:debian7-onbuild
02c34901 176#FROM williamyeh/ansible:centos7-onbuild
e6ab6fea 177#FROM williamyeh/ansible:centos6-onbuild
ebfd2bf2
WY
178
179
8287be90
WY
180# ==> Specify requirements filename; default = "requirements.yml"
181#ENV REQUIREMENTS requirements.yml
182
183# ==> Specify playbook filename; default = "playbook.yml"
184#ENV PLAYBOOK playbook.yml
ebfd2bf2 185
8287be90
WY
186# ==> Specify inventory filename; default = "/etc/ansible/hosts"
187#ENV INVENTORY inventory.ini
ebfd2bf2
WY
188
189# ==> Executing Ansible...
190RUN ansible-playbook-wrapper
191```
192
193
194
d3c54163
WY
195With 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!
196
ebfd2bf2
WY
197If better OS emulation (virtualization) isn't required, the Docker approach (containerization) should give you a more efficient Ansible experience.
198
d3c54163
WY
199
200
201## License
202
203Author: William Yeh <william.pjyeh@gmail.com>
204
205Licensed under the Apache License V2.0. See the [LICENSE file](LICENSE) for details.