]>
Commit | Line | Data |
---|---|---|
d3c54163 WY |
1 | Docker-Ansible base images |
2 | =================== | |
3 | ||
02c34901 WY |
4 | [![Build Status](https://travis-ci.org/William-Yeh/docker-ansible.svg?branch=master)](https://travis-ci.org/William-Yeh/docker-ansible) |
5 | ||
d3c54163 WY |
6 | |
7 | ## Summary | |
8 | ||
9a0d65e4 | 9 | Repository name in Docker Hub: **[williamyeh/ansible](https://registry.hub.docker.com/u/williamyeh/ansible/)** |
d3c54163 WY |
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 | ||
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 | ||
47 | Here comes a simplest working example for the impatient. | |
48 | ||
49 | First, choose a base image you'd like to begin with. For example, `williamyeh/ansible:ubuntu14.04-onbuild`. | |
50 | ||
51 | Second, put the following `Dockerfile` along with your playbook directory: | |
52 | ||
53 | ``` | |
54 | FROM williamyeh/ansible:ubuntu14.04-onbuild | |
55 | ||
56 | # ==> Specify playbook filename; default = "playbook.yml" | |
57 | #ENV PLAYBOOK playbook.yml | |
58 | ||
59 | # ==> Specify inventory filename; default = "/etc/ansible/hosts" | |
60 | #ENV INVENTORY inventory.ini | |
61 | ||
62 | # ==> Executing Ansible... | |
63 | RUN ansible-playbook-wrapper | |
64 | ``` | |
65 | ||
66 | Third, `docker build .` | |
67 | ||
68 | Done! | |
69 | ||
a78235d8 | 70 | For 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 [Travis CI](https://travis-ci.org/)’s Ubuntu 12.04 worker instances. |
c20fa492 WY |
71 | |
72 | ||
73 | ||
74 | ||
d3c54163 WY |
75 | ## Why yet another Ansible image for Docker? |
76 | ||
77 | 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? | |
78 | ||
79 | 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: | |
80 | ||
81 | - *Base OS image* - It provides only `centos:centos7` and `ubuntu:14.04`. Insufficent for me. | |
82 | ||
83 | - *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. | |
84 | ||
85 | Therefore, I built these Docker images on my own. | |
86 | ||
87 | ||
c20fa492 WY |
88 | ### Comparison: image size |
89 | ||
90 | ``` | |
91 | REPOSITORY TAG VIRTUAL SIZE | |
92 | --------------------------- ------------------- ------------ | |
93 | ansible/centos7-ansible stable 367.5 MB | |
94 | ansible/ubuntu14.04-ansible stable 286.6 MB | |
95 | ||
96 | williamyeh/ansible centos6-onbuild 264.2 MB | |
97 | williamyeh/ansible centos7-onbuild 275.3 MB | |
98 | williamyeh/ansible debian7-onbuild 134.4 MB | |
99 | williamyeh/ansible debian8-onbuild 178.3 MB | |
100 | williamyeh/ansible ubuntu12.04-onbuild 181.9 MB | |
101 | williamyeh/ansible ubuntu14.04-onbuild 238.3 MB | |
102 | ``` | |
103 | ||
104 | ||
d3c54163 WY |
105 | ## Usage |
106 | ||
107 | Used mostly as a *base image* for configuring, with Ansible, other software stack on some specified Linux distribution. | |
108 | ||
c20fa492 | 109 | 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: |
d3c54163 WY |
110 | |
111 | ```ruby | |
112 | # Vagrantfile | |
113 | ||
114 | Vagrant.configure(2) do |config| | |
115 | ||
116 | # ==> Choose a Vagrant box to emulate Linux distribution... | |
117 | config.vm.box = "ubuntu/trusty64" | |
118 | #config.vm.box = "hashicorp/precise64" | |
119 | #config.vm.box = "chef/debian-7.8" | |
02c34901 | 120 | #config.vm.box = "chef/centos-7.0" |
e6ab6fea WY |
121 | #config.vm.box = "chef/centos-6.6" |
122 | ||
d3c54163 WY |
123 | |
124 | # ==> Executing Ansible... | |
125 | config.vm.provision "ansible" do |ansible| | |
126 | ansible.playbook = "playbook.yml" | |
127 | end | |
128 | ||
129 | end | |
130 | ``` | |
131 | ||
ebfd2bf2 WY |
132 | Virtual machines can emulate a variety of Linux distributions with good quality, at the cost of runtime overhead. |
133 | ||
d3c54163 WY |
134 | |
135 | 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: | |
136 | ||
137 | ||
138 | ```dockerfile | |
139 | # Dockerfile | |
140 | ||
141 | # ==> Choose a base image to emulate Linux distribution... | |
142 | FROM williamyeh/ansible:ubuntu14.04 | |
143 | #FROM williamyeh/ansible:ubuntu12.04 | |
ebfd2bf2 | 144 | #FROM williamyeh/ansible:debian8 |
d3c54163 | 145 | #FROM williamyeh/ansible:debian7 |
02c34901 | 146 | #FROM williamyeh/ansible:centos7 |
e6ab6fea | 147 | #FROM williamyeh/ansible:centos6 |
d3c54163 | 148 | |
ebfd2bf2 | 149 | |
d3c54163 WY |
150 | # ==> Copying Ansible playbook... |
151 | WORKDIR /tmp | |
152 | COPY . /tmp | |
153 | ||
154 | # ==> Creating inventory file... | |
155 | RUN echo localhost > inventory | |
156 | ||
157 | # ==> Executing Ansible... | |
158 | RUN ansible-playbook -i inventory playbook.yml \ | |
159 | --connection=local --sudo | |
160 | ``` | |
161 | ||
ebfd2bf2 WY |
162 | Or, more simple with `onbuild` series: |
163 | ||
164 | ```dockerfile | |
165 | # Dockerfile | |
166 | ||
167 | # ==> Choose a base image to emulate Linux distribution... | |
168 | FROM williamyeh/ansible:ubuntu14.04-onbuild | |
169 | #FROM williamyeh/ansible:ubuntu12.04-onbuild | |
170 | #FROM williamyeh/ansible:debian8-onbuild | |
171 | #FROM williamyeh/ansible:debian7-onbuild | |
02c34901 | 172 | #FROM williamyeh/ansible:centos7-onbuild |
e6ab6fea | 173 | #FROM williamyeh/ansible:centos6-onbuild |
ebfd2bf2 WY |
174 | |
175 | ||
176 | # ==> Specify playbook filename; default = "playbook.yml" | |
177 | #ENV PLAYBOOK playbook.yml | |
178 | ||
179 | # ==> Specify inventory filename; default = "/etc/ansible/hosts" | |
180 | #ENV INVENTORY inventory.ini | |
181 | ||
182 | # ==> Executing Ansible... | |
183 | RUN ansible-playbook-wrapper | |
184 | ``` | |
185 | ||
186 | ||
187 | ||
d3c54163 WY |
188 | 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! |
189 | ||
ebfd2bf2 WY |
190 | If better OS emulation (virtualization) isn't required, the Docker approach (containerization) should give you a more efficient Ansible experience. |
191 | ||
d3c54163 WY |
192 | |
193 | ||
194 | ## License | |
195 | ||
196 | Author: William Yeh <william.pjyeh@gmail.com> | |
197 | ||
198 | Licensed under the Apache License V2.0. See the [LICENSE file](LICENSE) for details. |