From ebfd2bf236ddaf7206dc77877dc9eb2d07a0dec9 Mon Sep 17 00:00:00 2001 From: William Yeh Date: Tue, 28 Apr 2015 12:21:34 +0800 Subject: Add: onbuild and debian8. --- README.md | 49 ++++++++++++++++++++++++++-- Vagrantfile | 7 ++++ debian7-onbuild/Dockerfile | 47 ++++++++++++++++++++++++++ debian7-onbuild/ansible-playbook-wrapper | 30 +++++++++++++++++ debian7/Dockerfile | 8 ++--- debian8-onbuild/Dockerfile | 47 ++++++++++++++++++++++++++ debian8-onbuild/ansible-playbook-wrapper | 30 +++++++++++++++++ debian8/Dockerfile | 39 ++++++++++++++++++++++ ubuntu12.04-onbuild/Dockerfile | 43 ++++++++++++++++++++++++ ubuntu12.04-onbuild/ansible-playbook-wrapper | 30 +++++++++++++++++ ubuntu14.04-onbuild/Dockerfile | 43 ++++++++++++++++++++++++ ubuntu14.04-onbuild/ansible-playbook-wrapper | 30 +++++++++++++++++ 12 files changed, 397 insertions(+), 6 deletions(-) create mode 100644 debian7-onbuild/Dockerfile create mode 100755 debian7-onbuild/ansible-playbook-wrapper create mode 100644 debian8-onbuild/Dockerfile create mode 100755 debian8-onbuild/ansible-playbook-wrapper create mode 100644 debian8/Dockerfile create mode 100644 ubuntu12.04-onbuild/Dockerfile create mode 100755 ubuntu12.04-onbuild/ansible-playbook-wrapper create mode 100644 ubuntu14.04-onbuild/Dockerfile create mode 100755 ubuntu14.04-onbuild/ansible-playbook-wrapper diff --git a/README.md b/README.md index c303044..7dce9f8 100644 --- a/README.md +++ b/README.md @@ -14,11 +14,27 @@ This repository contains Dockerized [Ansible](https://github.com/ansible/ansible These are Docker images for [Ansible](https://github.com/ansible/ansible) software, installed in a selected Linux distributions. -- OS: Debian (wheezy), Ubuntu (precise, trusty). +- OS: Debian (jessie, wheezy), Ubuntu (trusty, precise). - Ansible: usually the latest version. +## Images and tags + +- normal series: + + - `williamyeh/ansible:debian8` + - `williamyeh/ansible:debian7` + - `williamyeh/ansible:ubuntu14.04` + - `williamyeh/ansible:ubuntu12.04` + +- onbuild series: + + - `williamyeh/ansible:debian8-onbuild` + - `williamyeh/ansible:debian7-onbuild` + - `williamyeh/ansible:ubuntu14.04-onbuild` + - `williamyeh/ansible:ubuntu12.04-onbuild` + ## Why yet another Ansible image for Docker? @@ -57,7 +73,8 @@ Vagrant.configure(2) do |config| end ``` -Virtual machines can emulate a variety of Linux distributions, at the cost of runtime overhead. +Virtual machines can emulate a variety of Linux distributions with good quality, at the cost of runtime overhead. + 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: @@ -68,8 +85,10 @@ Docker to be a rescue. Now, with these **williamyeh/ansible** series, we may tes # ==> Choose a base image to emulate Linux distribution... FROM williamyeh/ansible:ubuntu14.04 #FROM williamyeh/ansible:ubuntu12.04 +#FROM williamyeh/ansible:debian8 #FROM williamyeh/ansible:debian7 + # ==> Copying Ansible playbook... WORKDIR /tmp COPY . /tmp @@ -82,8 +101,34 @@ RUN ansible-playbook -i inventory playbook.yml \ --connection=local --sudo ``` +Or, more simple with `onbuild` series: + +```dockerfile +# Dockerfile + +# ==> Choose a base image to emulate Linux distribution... +FROM williamyeh/ansible:ubuntu14.04-onbuild +#FROM williamyeh/ansible:ubuntu12.04-onbuild +#FROM williamyeh/ansible:debian8-onbuild +#FROM williamyeh/ansible:debian7-onbuild + + +# ==> Specify playbook filename; default = "playbook.yml" +#ENV PLAYBOOK playbook.yml + +# ==> Specify inventory filename; default = "/etc/ansible/hosts" +#ENV INVENTORY inventory.ini + +# ==> Executing Ansible... +RUN ansible-playbook-wrapper +``` + + + 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! +If better OS emulation (virtualization) isn't required, the Docker approach (containerization) should give you a more efficient Ansible experience. + ## License diff --git a/Vagrantfile b/Vagrantfile index b198622..4d8c0a6 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -6,6 +6,13 @@ Vagrant.configure(2) do |config| docker build -t ansible:ubuntu14.04 ubuntu14.04 docker build -t ansible:ubuntu12.04 ubuntu12.04 + docker build -t ansible:debian8 debian8 docker build -t ansible:debian7 debian7 + + docker build -t ansible:ubuntu14.04-onbuild ubuntu14.04-onbuild + docker build -t ansible:ubuntu12.04-onbuild ubuntu12.04-onbuild + docker build -t ansible:debian8-onbuild debian8-onbuild + docker build -t ansible:debian7-onbuild debian7-onbuild + SHELL end diff --git a/debian7-onbuild/Dockerfile b/debian7-onbuild/Dockerfile new file mode 100644 index 0000000..1620990 --- /dev/null +++ b/debian7-onbuild/Dockerfile @@ -0,0 +1,47 @@ +# Dockerfile for building Ansible image for Debian 7 (wheezy), with as few additional software as possible. +# +# @see https://launchpad.net/~ansible/+archive/ubuntu/ansible +# +# Version 1.0 +# + + +# pull base image +FROM debian:wheezy + +MAINTAINER William Yeh + + +RUN echo "===> Installing python, sudo, and supporting tools..." && \ + apt-get update && \ + DEBIAN_FRONTEND=noninteractive \ + apt-get install -y \ + python python-yaml sudo \ + curl gcc python-pip python-dev && \ + \ + \ + echo "===> Installing Ansible..." && \ + pip install ansible && \ + \ + \ + echo "===> Removing unused APT resources..." && \ + apt-get -f -y --auto-remove remove curl gcc python-pip python-dev && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* /tmp/* && \ + \ + \ + echo "===> Adding hosts for convenience..." && \ + mkdir -p /etc/ansible && \ + echo '[local]\nlocalhost\n' > /etc/ansible/hosts + + +COPY ansible-playbook-wrapper /usr/local/bin/ + +ONBUILD RUN DEBIAN_FRONTEND=noninteractive apt-get update +ONBUILD WORKDIR /tmp +ONBUILD COPY . /tmp + + + +# default command: display Ansible version +CMD [ "ansible-playbook", "--version" ] diff --git a/debian7-onbuild/ansible-playbook-wrapper b/debian7-onbuild/ansible-playbook-wrapper new file mode 100755 index 0000000..bf137c8 --- /dev/null +++ b/debian7-onbuild/ansible-playbook-wrapper @@ -0,0 +1,30 @@ +#!/bin/sh +# +# Simple wrapper for executing ansible-playbook with local connection. +# +# USAGE: +# ansible-playbook-wrapper [other ansible-playbook arguments] +# +# ENVIRONMENT VARIABLES: +# +# - PLAYBOOK: playbook filename; default = "playbook.yml" +# - INVENTORY: inventory filename; default = "/etc/ansible/hosts" +# + + +if [ -z "$PLAYBOOK" ]; then + PLAYBOOK=playbook.yml +fi + + +if [ -z "$INVENTORY" ]; then + exec ansible-playbook \ + $PLAYBOOK \ + --connection=local \ + "$@" +else + exec ansible-playbook \ + -i $INVENTORY $PLAYBOOK \ + --connection=local \ + "$@" +fi diff --git a/debian7/Dockerfile b/debian7/Dockerfile index 72d3d31..afa69df 100644 --- a/debian7/Dockerfile +++ b/debian7/Dockerfile @@ -14,9 +14,9 @@ MAINTAINER William Yeh RUN echo "===> Installing python, sudo, and supporting tools..." && \ apt-get update && \ - DEBIAN_FRONTEND=noninteractive \ - apt-get install -y \ - python sudo \ + DEBIAN_FRONTEND=noninteractive \ + apt-get install -y \ + python python-yaml sudo \ curl gcc python-pip python-dev && \ \ \ @@ -27,7 +27,7 @@ RUN echo "===> Installing python, sudo, and supporting tools..." && \ echo "===> Removing unused APT resources..." && \ apt-get -f -y --auto-remove remove curl gcc python-pip python-dev && \ apt-get clean && \ - rm -rf /var/lib/apt/lists/* && \ + rm -rf /var/lib/apt/lists/* /tmp/* && \ \ \ echo "===> Adding hosts for convenience..." && \ diff --git a/debian8-onbuild/Dockerfile b/debian8-onbuild/Dockerfile new file mode 100644 index 0000000..04eadb5 --- /dev/null +++ b/debian8-onbuild/Dockerfile @@ -0,0 +1,47 @@ +# Dockerfile for building Ansible image for Debian 8 (jessie), with as few additional software as possible. +# +# @see https://launchpad.net/~ansible/+archive/ubuntu/ansible +# +# Version 1.0 +# + + +# pull base image +FROM debian:jessie + +MAINTAINER William Yeh + + +RUN echo "===> Installing python, sudo, and supporting tools..." && \ + apt-get update && \ + DEBIAN_FRONTEND=noninteractive \ + apt-get install -y \ + python python-yaml sudo \ + curl gcc python-pip python-dev && \ + \ + \ + echo "===> Installing Ansible..." && \ + pip install ansible && \ + \ + \ + echo "===> Removing unused APT resources..." && \ + apt-get -f -y --auto-remove remove curl gcc python-pip python-dev && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* /tmp/* && \ + \ + \ + echo "===> Adding hosts for convenience..." && \ + mkdir -p /etc/ansible && \ + echo '[local]\nlocalhost\n' > /etc/ansible/hosts + + +COPY ansible-playbook-wrapper /usr/local/bin/ + +ONBUILD RUN DEBIAN_FRONTEND=noninteractive apt-get update +ONBUILD WORKDIR /tmp +ONBUILD COPY . /tmp + + + +# default command: display Ansible version +CMD [ "ansible-playbook", "--version" ] diff --git a/debian8-onbuild/ansible-playbook-wrapper b/debian8-onbuild/ansible-playbook-wrapper new file mode 100755 index 0000000..bf137c8 --- /dev/null +++ b/debian8-onbuild/ansible-playbook-wrapper @@ -0,0 +1,30 @@ +#!/bin/sh +# +# Simple wrapper for executing ansible-playbook with local connection. +# +# USAGE: +# ansible-playbook-wrapper [other ansible-playbook arguments] +# +# ENVIRONMENT VARIABLES: +# +# - PLAYBOOK: playbook filename; default = "playbook.yml" +# - INVENTORY: inventory filename; default = "/etc/ansible/hosts" +# + + +if [ -z "$PLAYBOOK" ]; then + PLAYBOOK=playbook.yml +fi + + +if [ -z "$INVENTORY" ]; then + exec ansible-playbook \ + $PLAYBOOK \ + --connection=local \ + "$@" +else + exec ansible-playbook \ + -i $INVENTORY $PLAYBOOK \ + --connection=local \ + "$@" +fi diff --git a/debian8/Dockerfile b/debian8/Dockerfile new file mode 100644 index 0000000..c49558a --- /dev/null +++ b/debian8/Dockerfile @@ -0,0 +1,39 @@ +# Dockerfile for building Ansible image for Debian 8 (jessie), with as few additional software as possible. +# +# @see https://launchpad.net/~ansible/+archive/ubuntu/ansible +# +# Version 1.0 +# + + +# pull base image +FROM debian:jessie + +MAINTAINER William Yeh + + +RUN echo "===> Installing python, sudo, and supporting tools..." && \ + apt-get update && \ + DEBIAN_FRONTEND=noninteractive \ + apt-get install -y \ + python python-yaml sudo \ + curl gcc python-pip python-dev && \ + \ + \ + echo "===> Installing Ansible..." && \ + pip install ansible && \ + \ + \ + echo "===> Removing unused APT resources..." && \ + apt-get -f -y --auto-remove remove curl gcc python-pip python-dev && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* /tmp/* && \ + \ + \ + echo "===> Adding hosts for convenience..." && \ + mkdir -p /etc/ansible && \ + echo '[local]\nlocalhost\n' > /etc/ansible/hosts + + +# default command: display Ansible version +CMD [ "ansible-playbook", "--version" ] diff --git a/ubuntu12.04-onbuild/Dockerfile b/ubuntu12.04-onbuild/Dockerfile new file mode 100644 index 0000000..f7a5aa0 --- /dev/null +++ b/ubuntu12.04-onbuild/Dockerfile @@ -0,0 +1,43 @@ +# Dockerfile for building Ansible image for Ubuntu 12.04 (presice), with as few additional software as possible. +# +# @see https://launchpad.net/~ansible/+archive/ubuntu/ansible +# +# Version 1.0 +# + + +# pull base image +FROM ubuntu:12.04 + +MAINTAINER William Yeh + + +RUN echo "===> Adding Ansible's PPA..." && \ + echo "deb http://ppa.launchpad.net/ansible/ansible/ubuntu precise main" | tee /etc/apt/sources.list.d/ansible.list && \ + echo "deb-src http://ppa.launchpad.net/ansible/ansible/ubuntu precise main" | tee -a /etc/apt/sources.list.d/ansible.list && \ + apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 7BB9C367 && \ + DEBIAN_FRONTEND=noninteractive apt-get update && \ + \ + \ + echo "===> Installing Ansible (and sudo)..." && \ + apt-get install -y ansible sudo && \ + \ + \ + echo "===> Removing Ansible PPA..." && \ + rm -rf /var/lib/apt/lists/* /etc/apt/sources.list.d/ansible.list && \ + \ + \ + echo "===> Adding hosts for convenience..." && \ + echo '[local]\nlocalhost\n' > /etc/ansible/hosts + + +COPY ansible-playbook-wrapper /usr/local/bin/ + +ONBUILD RUN DEBIAN_FRONTEND=noninteractive apt-get update +ONBUILD WORKDIR /tmp +ONBUILD COPY . /tmp + + + +# default command: display Ansible version +CMD [ "ansible-playbook", "--version" ] diff --git a/ubuntu12.04-onbuild/ansible-playbook-wrapper b/ubuntu12.04-onbuild/ansible-playbook-wrapper new file mode 100755 index 0000000..bf137c8 --- /dev/null +++ b/ubuntu12.04-onbuild/ansible-playbook-wrapper @@ -0,0 +1,30 @@ +#!/bin/sh +# +# Simple wrapper for executing ansible-playbook with local connection. +# +# USAGE: +# ansible-playbook-wrapper [other ansible-playbook arguments] +# +# ENVIRONMENT VARIABLES: +# +# - PLAYBOOK: playbook filename; default = "playbook.yml" +# - INVENTORY: inventory filename; default = "/etc/ansible/hosts" +# + + +if [ -z "$PLAYBOOK" ]; then + PLAYBOOK=playbook.yml +fi + + +if [ -z "$INVENTORY" ]; then + exec ansible-playbook \ + $PLAYBOOK \ + --connection=local \ + "$@" +else + exec ansible-playbook \ + -i $INVENTORY $PLAYBOOK \ + --connection=local \ + "$@" +fi diff --git a/ubuntu14.04-onbuild/Dockerfile b/ubuntu14.04-onbuild/Dockerfile new file mode 100644 index 0000000..c0e400f --- /dev/null +++ b/ubuntu14.04-onbuild/Dockerfile @@ -0,0 +1,43 @@ +# Dockerfile for building Ansible image for Ubuntu 14.04 (trusty), with as few additional software as possible. +# +# @see https://launchpad.net/~ansible/+archive/ubuntu/ansible +# +# Version 1.0 +# + + +# pull base image +FROM ubuntu:14.04 + +MAINTAINER William Yeh + + +RUN echo "===> Adding Ansible's PPA..." && \ + echo "deb http://ppa.launchpad.net/ansible/ansible/ubuntu trusty main" | tee /etc/apt/sources.list.d/ansible.list && \ + echo "deb-src http://ppa.launchpad.net/ansible/ansible/ubuntu trusty main" | tee -a /etc/apt/sources.list.d/ansible.list && \ + apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 7BB9C367 && \ + DEBIAN_FRONTEND=noninteractive apt-get update && \ + \ + \ + echo "===> Installing Ansible..." && \ + apt-get install -y ansible && \ + \ + \ + echo "===> Removing Ansible PPA..." && \ + rm -rf /var/lib/apt/lists/* /etc/apt/sources.list.d/ansible.list && \ + \ + \ + echo "===> Adding hosts for convenience..." && \ + echo '[local]\nlocalhost\n' > /etc/ansible/hosts + + +COPY ansible-playbook-wrapper /usr/local/bin/ + +ONBUILD RUN DEBIAN_FRONTEND=noninteractive apt-get update +ONBUILD WORKDIR /tmp +ONBUILD COPY . /tmp + + + +# default command: display Ansible version +CMD [ "ansible-playbook", "--version" ] diff --git a/ubuntu14.04-onbuild/ansible-playbook-wrapper b/ubuntu14.04-onbuild/ansible-playbook-wrapper new file mode 100755 index 0000000..bf137c8 --- /dev/null +++ b/ubuntu14.04-onbuild/ansible-playbook-wrapper @@ -0,0 +1,30 @@ +#!/bin/sh +# +# Simple wrapper for executing ansible-playbook with local connection. +# +# USAGE: +# ansible-playbook-wrapper [other ansible-playbook arguments] +# +# ENVIRONMENT VARIABLES: +# +# - PLAYBOOK: playbook filename; default = "playbook.yml" +# - INVENTORY: inventory filename; default = "/etc/ansible/hosts" +# + + +if [ -z "$PLAYBOOK" ]; then + PLAYBOOK=playbook.yml +fi + + +if [ -z "$INVENTORY" ]; then + exec ansible-playbook \ + $PLAYBOOK \ + --connection=local \ + "$@" +else + exec ansible-playbook \ + -i $INVENTORY $PLAYBOOK \ + --connection=local \ + "$@" +fi -- cgit v1.2.3