]>
Commit | Line | Data |
---|---|---|
d3c54163 WY |
1 | Docker-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 | 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 | ||
ae06b63d | 19 | - OS: Debian (jessie, wheezy), Ubuntu (trusty, precise), CentOS (7, 6), Alpine (3). |
d3c54163 | 20 | |
aa3cb4d5 | 21 | - Ansible: usually the latest version (I didn't pin any specific version). |
d3c54163 WY |
22 | |
23 | ||
ebfd2bf2 WY |
24 | ## Images and tags |
25 | ||
aa3cb4d5 | 26 | - Normal series: |
ebfd2bf2 WY |
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` |
ae06b63d | 34 | - `williamyeh/ansible:alpine3` |
ebfd2bf2 | 35 | |
aa3cb4d5 | 36 | - Onbuild series: |
ebfd2bf2 WY |
37 | |
38 | - `williamyeh/ansible:debian8-onbuild` | |
39 | - `williamyeh/ansible:debian7-onbuild` | |
40 | - `williamyeh/ansible:ubuntu14.04-onbuild` | |
41 | - `williamyeh/ansible:ubuntu12.04-onbuild` | |
02c34901 | 42 | - `williamyeh/ansible:centos7-onbuild` |
e6ab6fea | 43 | - `williamyeh/ansible:centos6-onbuild` |
ae06b63d | 44 | - `williamyeh/ansible:alpine3-onbuild` |
ebfd2bf2 | 45 | |
d3c54163 | 46 | |
c20fa492 WY |
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 | ||
8287be90 WY |
58 | # ==> Specify requirements filename; default = "requirements.yml" |
59 | #ENV REQUIREMENTS requirements.yml | |
c20fa492 | 60 | |
8287be90 WY |
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 | |
c20fa492 WY |
66 | |
67 | # ==> Executing Ansible... | |
68 | RUN ansible-playbook-wrapper | |
69 | ``` | |
70 | ||
71 | Third, `docker build .` | |
72 | ||
73 | Done! | |
74 | ||
aa3cb4d5 | 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. |
c20fa492 WY |
76 | |
77 | ||
78 | ||
79 | ||
d3c54163 WY |
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 | ||
2fd99bb9 | 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.” |
d3c54163 | 93 | |
c20fa492 WY |
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 | ||
ae06b63d | 102 | williamyeh/ansible alpine3-onbuild 66.4 MB |
c20fa492 WY |
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 | ||
d3c54163 WY |
112 | ## Usage |
113 | ||
aa3cb4d5 | 114 | Used mostly as a *base image* for configuring other software stack on some specified Linux distribution(s). |
d3c54163 | 115 | |
c20fa492 | 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: |
d3c54163 WY |
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" | |
ae06b63d WY |
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" | |
e6ab6fea | 131 | |
d3c54163 WY |
132 | |
133 | # ==> Executing Ansible... | |
134 | config.vm.provision "ansible" do |ansible| | |
135 | ansible.playbook = "playbook.yml" | |
136 | end | |
137 | ||
138 | end | |
139 | ``` | |
140 | ||
ebfd2bf2 WY |
141 | Virtual machines can emulate a variety of Linux distributions with good quality, at the cost of runtime overhead. |
142 | ||
d3c54163 WY |
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 | |
ebfd2bf2 | 153 | #FROM williamyeh/ansible:debian8 |
d3c54163 | 154 | #FROM williamyeh/ansible:debian7 |
02c34901 | 155 | #FROM williamyeh/ansible:centos7 |
e6ab6fea | 156 | #FROM williamyeh/ansible:centos6 |
ae06b63d | 157 | #FROM williamyeh/ansible:alpine3 |
d3c54163 | 158 | |
ebfd2bf2 | 159 | |
d3c54163 WY |
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 | ||
ebfd2bf2 WY |
172 | Or, more simple with `onbuild` series: |
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 | |
02c34901 | 182 | #FROM williamyeh/ansible:centos7-onbuild |
e6ab6fea | 183 | #FROM williamyeh/ansible:centos6-onbuild |
ae06b63d | 184 | #FROM williamyeh/ansible:alpine3-onbuild |
ebfd2bf2 WY |
185 | |
186 | ||
8287be90 WY |
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 | |
ebfd2bf2 | 192 | |
8287be90 WY |
193 | # ==> Specify inventory filename; default = "/etc/ansible/hosts" |
194 | #ENV INVENTORY inventory.ini | |
ebfd2bf2 WY |
195 | |
196 | # ==> Executing Ansible... | |
197 | RUN ansible-playbook-wrapper | |
198 | ``` | |
199 | ||
200 | ||
201 | ||
d3c54163 WY |
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 | ||
ebfd2bf2 WY |
204 | If better OS emulation (virtualization) isn't required, the Docker approach (containerization) should give you a more efficient Ansible experience. |
205 | ||
d3c54163 WY |
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. |